using
System;
using
System.IO;
public
class
Log
{
public
Log()
{
logName =
""
;
}
public
Log(
string
prefilename)
{
logName = prefilename;
}
private
string
path = System.AppDomain.CurrentDomain.BaseDirectory +
"Result\\"
;
public
void
clearTextfile()
{
try
{
if
(Directory.Exists(path))
{
DirectoryInfo dir =
new
DirectoryInfo(path);
FileInfo[] txtfiles = dir.GetFiles(
"*.txt"
);
foreach
(FileInfo f
in
txtfiles)
{
File.Delete(f.FullName);
}
}
}
catch
{
}
}
public
string
logName{
get
;
set
;}
public
void
WriteLog(
string
msg)
{
try
{
if
(!Directory.Exists(path))
Directory.CreateDirectory(path);
string
logfilename = path +logName+
".txt"
;
FileStream fs =
null
;
if
(File.Exists(logfilename))
{
fs =
new
FileStream(logfilename, FileMode.Append, FileAccess.Write);
}
else
{
fs =
new
FileStream(logfilename, FileMode.Create, FileAccess.Write);
}
StreamWriter sw =
new
StreamWriter(fs);
sw.WriteLine(msg);
sw.Flush();
sw.Close();
fs.Close();
}
catch
(Exception ex)
{
throw
ex;
}
}
}