且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Windows Phone 实用开发技巧(22):使用日志记录当前信息与异常信息

更新时间:2022-01-25 03:32:53

What is logging ?

 Logging is the felling, skidding, on-site processing, and loading of trees or logs onto trucks. And since windows phone is much more event driven. you can find more information in Event Logging.

Why to use logging ? 

Exception is everywhere in common software development. A good logging tool may helps a lot in solving problems. Here I recommend logging tool in WP7Contrib

Here I created a helper class to do better and easier logging.

Windows Phone 实用开发技巧(22):使用日志记录当前信息与异常信息 

Windows Phone 实用开发技巧(22):使用日志记录当前信息与异常信息 

We can log common information as well as Exception simply by pass different parameter. We can also log device information since it may be help in finding which device goes wrong. 

How to use it ?

First, we should add dll reference to our main project, shown as follow:

Windows Phone 实用开发技巧(22):使用日志记录当前信息与异常信息 

After that, we manually generate a DivideBvZeroException, shown as below: 

Windows Phone 实用开发技巧(22):使用日志记录当前信息与异常信息 

Here, I use LoggingHelper(shown before) class  to log exception.As we run the app, we can find exception both in output and log.dat which is the file store logging.

Windows Phone 实用开发技巧(22):使用日志记录当前信息与异常信息 

Windows Phone 实用开发技巧(22):使用日志记录当前信息与异常信息 

Ok, it is very simple to use. you can find source code here.




    本文转自xshf12345 51CTO博客,原文链接:http://blog.51cto.com/alexis/672033,如需转载请自行联系原作者