Viral Sarvaiya
Viral Sarvaiya

Reputation: 781

Creating Error log in wpf application

I am creating a wpf application and in which i have to create a error log file for my application.

How can i create automatically error log file in specific folder in date wise in wpf?

In web we create a error page and then create the error file but i have no idea that how can we create it in WPF.

Upvotes: 2

Views: 6470

Answers (2)

Robert Rossney
Robert Rossney

Reputation: 96890

First, take a look at the Trace and Debug classes in System.Diagnostics. A lot of the time, when people say they want to implement error-logging, what they really mean is that they want to implement tracing or debugging: the ability to turn debugging features on and off at compile time, and to reroute trace output at runtime is pretty powerful, and using System.Diagnostics is a whole lot easier than developing all that functionality yourself.

Second, whether you're going to use Trace or just write to a StreamWriter, look at Environment.SpecialFolder and Path.GetTempPath.

And yes, as sll noted, look at log4net too.

Upvotes: 2

sll
sll

Reputation: 62544

Take a look at the log4net, it allows easily setup log output in the file or another output stream like Event Log, Debug output...

If you want to do it yourself:

System.IO.StreamWriter file = new System.IO.StreamWriter("yourlog.log", true);

Upvotes: 6

Related Questions