Re: TraceListener issue
From: Mullin Yu (mullin_yu_at_ctil.com)
Date: 02/21/04
- Next message: Michael A. Covington: "Re: A mutex puzzle; single instance of application"
- Previous message: Chris R: "Re: strings in .Net"
- In reply to: Dmitriy Lapshin [C# / .NET MVP]: "Re: TraceListener issue"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 21 Feb 2004 13:09:49 +0800
i tried Trace.Close();
but, still having error when clicking second tme of the button.
the error is:
Cannot write to a closed TextWriter
therefore, it seems that i can't close it.
thanks!
"Dmitriy Lapshin [C# / .NET MVP]" <x-code@no-spam-please.hotpop.com> wrote
in message news:%23L0e3g69DHA.1052@TK2MSFTNGP12.phx.gbl...
> Hi,
>
> You can try closing the stream by using the Trace's Close method, not the
> FileStream's one.
> You don't need an explicit call to Flush then.
>
> --
> Dmitriy Lapshin [C# / .NET MVP]
> X-Unity Test Studio
> http://www.x-unity.net/teststudio.aspx
> Bring the power of unit testing to VS .NET IDE
>
> "Mullin Yu" <mullin_yu@ctil.com> wrote in message
> news:ujXKuh59DHA.2480@TK2MSFTNGP12.phx.gbl...
> > i have a problem with TraceListener. when i close the FileStream, i will
> > have the error:
> > "Cannot access a closed file"
> >
> > but, if i remarks the statement => no closing the FileStream, i will
have
> > another error:
> > "The process cannot access the file "C:\MyAppsTraceLog.log" because it
is
> > being used by another process."
> >
> > Remind that it's ok when i click the button once. the problem arises
when
> > clicking at the second time.
> >
> > my coding is:
> > private void button1_Click(object sender, System.EventArgs e)
> >
> > {
> >
> > // Create a TextWriteTraceListener to
> >
> > // capture all Debug and Trace messages
> >
> > // Define our tracing log file
> >
> > System.IO.FileStream traceLog = new
> > System.IO.FileStream(@"C:\MyAppsTraceLog.log",
> >
> > System.IO.FileMode.OpenOrCreate);
> >
> > // Instantiate a new TextWriterTraceListener and specify the output
> location
> >
> > TextWriterTraceListener traceListener = new
> > TextWriterTraceListener(traceLog);
> >
> > // Add Listener to the Listeners collection
> >
> > Trace.Listeners.Add(traceListener);
> >
> > // Send our tracing messages
> >
> > Trace.WriteLine("Trace Message 1");
> >
> > Debug.WriteLine("You are here.");
> >
> > Trace.WriteLine("Trace Message 2");
> >
> > // Flush the listners buffer and close the output
> >
> > Trace.Flush();
> >
> > // if remark => file is accessed by another process
> >
> > // traceLog.Close()
> >
> > traceLog.Close();
> >
> > }
> >
> >
>
- Next message: Michael A. Covington: "Re: A mutex puzzle; single instance of application"
- Previous message: Chris R: "Re: strings in .Net"
- In reply to: Dmitriy Lapshin [C# / .NET MVP]: "Re: TraceListener issue"
- Messages sorted by: [ date ] [ thread ]