开发者

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.


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);


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜