3

Possible Duplicate:
TextWriterTraceListener and trace filenames with GUIDs

I am using System.Diagnostics to trace the each n every method in my application. Tracing is working fine in the desired log file i.e xyz.log but at the same time multiple log are getting creating with Guidxyz.log.

My application is a powerpoint addin. Tracing will happen as long as user is working on it.

How can I prevent this from happening?

Sample code:

string userDirectoryPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicatio??nData),
UserSettings.GetApplicationSettingsValue("AppFolder"));

string fileName = Path.Combine(Path.Combine(userDirectoryPath,
UserSettings.GetApplicationSettingsValue("LogFolder")), "ICAddInLog.log");

Trace.Listeners.Add(new TextWriterTraceListener(fileName));

Trace.WriteLine(string.Format(
    "{0} \r\n\r\n Title: {1} \r\n\r\n Message: {2} \r\n\r\n TimeStamp: {3} \r\n\r\n {4}", 
    "---------------Tracing-------------------",
    title, 
    logText, 
    DateTime.Now, 
    "-----End"));
Community
  • 1
  • 1
Tarun
  • 393
  • 1
  • 6
  • 22
  • Please add some code on how you're setting it up. This trace listener will use a specified log file name: http://msdn.microsoft.com/en-us/library/dt303dc6.aspx –  Sep 20 '11 at 08:44
  • {string userDirectoryPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), UserSettings.GetApplicationSettingsValue("AppFolder")); string fileName = Path.Combine(Path.Combine(userDirectoryPath, UserSettings.GetApplicationSettingsValue("LogFolder")), "ICAddInLog.log"); Trace.Listeners.Add(new TextWriterTraceListener(fileName)); Trace.WriteLine(string.Format("{0} \r\n\r\n Title: {1} \r\n\r\n Message: {2} \r\n\r\n TimeStamp: {3} \r\n\r\n {4}","---------------Tracing-------------------", title, logText, DateTime.Now, "-----End")); } – Tarun Sep 20 '11 at 09:00
  • 1
    This was answered here: http://stackoverflow.com/questions/2341110/textwritertracelistener-and-trace-filenames-with-guids –  Sep 20 '11 at 09:30

0 Answers0