I'm working on a .NET v3.5 winforms app and would like to leverage some support for:
a) logging (to file & to perhaps windows events)
b) error handling / exception handling framework - to assist in distinguishing messages that can be shown to user versus handled within the code and logged
c) a bonus extra would be how to captu开发者_StackOverflow社区re/buildup serious errors to me via a server side web-service (similar to firefox when it asks you to feedback issues to the developers) - however if this doubles the complexity of what I'm asking for drop this requirement
Things I'm aware of include:
- log4net - seems popular but not sure if it helps with my requirement b)
- enterprise library - which I've looked at however it seems a bit heavy (like overkill)
thanks
I used to use both, but finally dropped EntLib in favor of log4net, as it's IMHO easer to use, configure and more lightweight.
Anyway, both libs will be OK, it's more of w personal justification for given project.
I'm biased, of course. But do yourself a favor and look at my logging framework. It's a lot easier to use than some other frameworks. It also comes with a sample Windows application that displays logs in real-time. There is also a Visual Studio plugin for viewing logs. It's also easy to send logs to a web service or whatever else you'd like. (I have some sample code for logging to Twitter, for example.)
+1 for log4net.
Regarding (b), I tend to define my own custom exceptions (all derived from the same base class e.g. "BusinessException") that are raised by the BLL for errors that need to be communicated to the user (input violates business rule, user authorization failed, ...). If the BLL is deployed as a Web Service, such exceptions are wrapped in a SOAP fault with a client(SOAP 1.1)/sender(SOAP 1.2) fault code.
Then in the UI tier, any BusinessException or FaultException with FaultCode.IsSenderFault = true indicates that the error message should be displayed to the end user. Any other exceptions are logged, and a generic message ("something bad happened") is shown to the end user.
Personally I think that distinguishing messages that are to be shown to the user can only sensibly be done in an application-specific way such as the above.
Regarding (c) you could write a custom log4net appender that sends serious errors to your web service (possibly asynchronously via MSMQ).
EDIT
In response to the comment, I don't know of any 3rd party framework that does this; we do it with a very lightweight in-house framework (which also has other basic stuff like a thin provider-model API around log4net so that our in-house code is not explicitly dependent on log4net and we will be able to switch to a different logging framework if a better one emerges, or if our app is deployed to sites where administrators prefer a different one).
Log4net is my favorite. Highly customizable, easy to use.
As for a web service to aggregate the log incident report, I was faced with the very same problem and eventually I created a service myself: bugcollect.com. You can download a the log4net appended from the site and see for your self. The service does report analysis and aggregates similar report into buckets. You can set up email notifications when a new report, a new bucket or a new source was submitted. You can also set up a response to a bucket and this response will be returned to the application when a similar incident is encountered, for instance instructing the user to download a newer version. The service has a RESTful interface to submit reports, but for .Net, Java, log4net and log4j there are free client libraries available to download. You can try either a free account with limited features or enter the promo code BETA for a fully functionality trial.
精彩评论