views:

420

answers:

5

Hi,

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 capture/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

+1  A: 

I think this question will help you out: http://stackoverflow.com/questions/2107220/how-should-i-log-exceptions-in-asp-net

Andrew
I'm actually doing a WinForms app?
Greg
+2  A: 

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.

Bolek Tekielski
did log4net help you out with differentiating between the text you may want a user to see, versus what you want in a log file that may get shipped back to a developer? thanks
Greg
Take a look on it's documentation, http://logging.apache.org/log4net/release/manual/configuration.html Basically, you can achieve what you want with different appenders and filtering logs, as explained in official documentation.
Bolek Tekielski
A: 

+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).

Joe
Thanks - your answer to my Q2 was exactly the type of thing I'm interested in. Is there no good existing very lightweight framework that addresses this you know of? (versus rolling your own)
Greg
+1  A: 

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.

Remus Rusanu
+2  A: 

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

TheObjectGuy
Does it provide ny specific support for my part b) requirement?
Greg
@Greg I think part b is something that is very application specific. My framework doesn't address that. You'll need to determine how to handle each exception, and what / whether to show the user information about it.
TheObjectGuy
thanks for responding
Greg