0

I am writing a small program in C# and as a part of it I need it to write data out to a log file. for this I am using the next command:

 Trace.Listeners.Add(new TextWriterTraceListener(Constants.LOG_FILE_NAME));
 Trace.AutoFlush = true;
 Trace.Indent();
 Trace.WriteLine("\n~~~~~~~~~~~~~~\n" + DateTime.Now + ": start writing to file");

It works perfectly when running from visual studio, but when I am compiling a release version, it does not writing the log file and instead (sometimes) I am getting a file with the name 0 and zero size, and there is no content inside it.

I am suspecting this is a permissions problem, how can I check if this is the reason?
If someone familiar with this issue and can help me with that I'll be thankful.

Edit
I forgot the mention that the 'Define Trace Constant' is checked in the build properties under all the configurations, so this can't be the reason.

user2979757
  • 783
  • 2
  • 8
  • 12

1 Answers1

0

You'll need to define a trace switch, and then add configuration to your app.config to enable the switch. Instructions are here: http://msdn.microsoft.com/en-us/library/t06xyy08%28v=vs.110%29.aspx

CJBS
  • 15,147
  • 6
  • 86
  • 135