Using Trace to write to a file : DOTNET
This is a discussion on Using Trace to write to a file within the DOTNET forums in Framework and Interface Programming category; Hi all, I'm trying to use the Trace class to log messages to a simple text file. I need to be able to provide a custom filename to be used. I've created a TextWriterTraceListener and added it to the Trace.Listeners collections but nothing ever seems to get written to the file. The file does get created, but calling the Write methods doesn't seem to do anything. Can anyone tell me why the code below shouldn't work? TextWriterTraceListener textListener = new TextWriterTraceListener("Hello.txt"); Trace.Listeners.Add(textListener); // Doesn't Work Trace.WriteLine("Hello World"); // Doesn't Work textListener.WriteLine("Hello World"); Many thanks all Simon...
| DOTNET Discussion forums related to Microsoft Dot net technologies, CSharp and other related items |
![]() |
| | LinkBack | Thread Tools |
|
#1
| |||
| |||
| I'm trying to use the Trace class to log messages to a simple text file. I need to be able to provide a custom filename to be used. I've created a TextWriterTraceListener and added it to the Trace.Listeners collections but nothing ever seems to get written to the file. The file does get created, but calling the Write methods doesn't seem to do anything. Can anyone tell me why the code below shouldn't work? TextWriterTraceListener textListener = new TextWriterTraceListener("Hello.txt"); Trace.Listeners.Add(textListener); // Doesn't Work Trace.WriteLine("Hello World"); // Doesn't Work textListener.WriteLine("Hello World"); Many thanks all Simon |
|
#2
| |||
| |||
| Hello, The writer buffers messages in memory. Call the Flush method or set the AutoFlush property to true on the underlying writer. Kind regards, Henning Krause "Simon" <nothanks@hotmail.com> wrote in message news:e4c3qiwxHHA.4928@TK2MSFTNGP03.phx.gbl... > Hi all, > > I'm trying to use the Trace class to log messages to a simple text file. I > need to be able to provide a custom filename to be used. I've created a > TextWriterTraceListener and added it to the Trace.Listeners collections > but nothing ever seems to get written to the file. > > The file does get created, but calling the Write methods doesn't seem to > do anything. > > Can anyone tell me why the code below shouldn't work? > > TextWriterTraceListener textListener = new > TextWriterTraceListener("Hello.txt"); > > Trace.Listeners.Add(textListener); > > // Doesn't Work > Trace.WriteLine("Hello World"); > > // Doesn't Work > textListener.WriteLine("Hello World"); > > Many thanks all > > Simon |
|
#3
| |||
| |||
| In general, I hate config files, but they lend themselves nicely to tracing. <system.diagnostics> <trace autoflush="true"> <listeners> <add name="TextWriterTraceListener" type="System.Diagnostics.TextWriterTraceListener, System, Version=2.0.50727.42, Culture=neutral, PublicKeyToken=b77a5c561934e089" initializeData="C:\myFunkyTrace.log" /> </listeners> </trace> </system.diagnostics> No need to muck around in code. |
|
#4
| |||
| |||
| You need to Call the Flush Method "Simon" <nothanks@hotmail.com> wrote in message news:e4c3qiwxHHA.4928@TK2MSFTNGP03.phx.gbl... > Hi all, > > I'm trying to use the Trace class to log messages to a simple text file. I > need to be able to provide a custom filename to be used. I've created a > TextWriterTraceListener and added it to the Trace.Listeners collections > but nothing ever seems to get written to the file. > > The file does get created, but calling the Write methods doesn't seem to > do anything. > > Can anyone tell me why the code below shouldn't work? > > TextWriterTraceListener textListener = new > TextWriterTraceListener("Hello.txt"); > > Trace.Listeners.Add(textListener); > > // Doesn't Work > Trace.WriteLine("Hello World"); > > // Doesn't Work > textListener.WriteLine("Hello World"); > > Many thanks all > > Simon > |
![]() |
| Thread Tools | |
| |
| ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| NUnit GUI Runner - Trace Output and Internal Trace?? | usenet | CSharp | 0 | 11-19-2007 04:39 PM |
| Large MOSS trace log file | usenet | Sharepoint | 3 | 10-18-2007 09:17 AM |
| Trace.Write..... | usenet | DOTNET | 3 | 10-05-2006 04:36 PM |
| Re: Trace: Can anyone suggest a good tool to catch trace messages? | usenet | DOTNET | 0 | 10-27-2003 04:04 PM |
| Re: Trace: Can anyone suggest a good tool to catch trace messages? | usenet | DOTNET | 0 | 10-12-2003 07:46 PM |


