public static void GenerateUniqueLogFile()
{
Assembly executingAssembly = Assembly.GetExecutingAssembly();
FileInfo fileInfo = new FileInfo(executingAssembly.Location);
string logFileName = fileInfo.Name + "_" + DateTime.Now.ToString("dd_MMM_yyyy_hh_mm") + ".log";
string logFileFullPath = Path.Combine(fileInfo.DirectoryName, logFileName);
StreamWriter logWriter = new StreamWriter(logFileFullPath);
TextWriterTraceListener listener = new TextWriterTraceListener(logWriter);
Trace.Listeners.Add(listener);
Trace.AutoFlush = true;
}
Call GenerateUniqueLogFile() function on first line of Main function :-)
{
Assembly executingAssembly = Assembly.GetExecutingAssembly();
FileInfo fileInfo = new FileInfo(executingAssembly.Location);
string logFileName = fileInfo.Name + "_" + DateTime.Now.ToString("dd_MMM_yyyy_hh_mm") + ".log";
string logFileFullPath = Path.Combine(fileInfo.DirectoryName, logFileName);
StreamWriter logWriter = new StreamWriter(logFileFullPath);
TextWriterTraceListener listener = new TextWriterTraceListener(logWriter);
Trace.Listeners.Add(listener);
Trace.AutoFlush = true;
}
Call GenerateUniqueLogFile() function on first line of Main function :-)
No comments:
Post a Comment