Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to create and write the information, error and warning into the log file in winforms.
Have tried the below code but still i am not able to log the errors.

What I have tried:

C#
Trace.TraceInformation("Your Information");
                Trace.TraceError("Your Error");
                Trace.TraceWarning("Your Warning");
Posted
Updated 15-Nov-16 20:26pm

To utilize Trace capabilities of the .NET framework, you first have to set up a trace listener - an actual storage to where the trace messages will go...
In you code there is only messages, but nowhere to see one who listens to those messages...
Se the simple, but complete sample at MSDN...
Trace Class (System.Diagnostics)[^]
 
Share this answer
 
Comments
Alex Sprint 16-Nov-16 4:04am    
Thanks peter the link was of great help :)
You need to set up a Trace Listener[^] to determine where you want the output to go. Without that, your output just goes to the default listener, which is the debug window. There are many types of Listener for the Event Log, a Log File, the Console, etc... have a read from the link, and I'm sure you'll be able to take it from there.
 
Share this answer
 
Comments
Kornfeld Eliyahu Peter 16-Nov-16 3:12am    
"goes to the default listener, which is the debug window" - while debugging...
However tracing is much more for production health monitoring and in that case if no listener it goes nowhere...
Alex Sprint 16-Nov-16 4:11am    
Thanks for the solution Mick :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900