Best approach for logging / error handling framework for C # .NET v3.5 application? (corporate library / log4net /?)

I am working on a .NET v3.5 winforms application and would like to use some support for:

a) logging (for files and possibly Windows events)

b) error handling / exception handling framework - helps distinguish between messages that can be displayed to the user, or processed in code and logged

c) an additional bonus will be how to capture / create serious errors for me through a server side web service (similar to firefox when it asks you for feedback from developers), however, if it doubles the complexity of what I ask refuse this requirement

Things I know about include:

  • log4net - seems popular, but not sure if it helps with my requirement b)
  • The corporate library I was looking at, however, it seems a bit heavy (like overkill).

thanks

+4
source share
4 answers

+1 for log4net.

In relation to (b), I tend to define my own custom exceptions (all derived from the same base class, for example, “BusinessException”) that raise BLLs for errors that should be passed to the user (the entry violates the business rule, user authorization fails , ...). If the BLL is deployed as a web service, these exceptions result from a SOAP error with the client error code (SOAP 1.1) / sender (SOAP 1.2).

Then at the UI level, 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 displayed to the end user.

Personally, I believe that the distinctive messages that should be displayed to the user can be reasonably executed only depending on the application, for example above.

Regarding (c), you can write your own custom log4net file that sends serious errors to your web service (possibly asynchronously via MSMQ).

EDIT

In response to the comment, I do not know of any third-party structure that does this; we do this with a very lightweight internal framework (which also has other basic things, such as a thin provider-model API around log4net, so that our internal code is clearly independent of log4net, and we can switch to another if the best one appears, or if our application is deployed to sites where administrators prefer something else).

+1
source

I used to use both, but finally, EntLib fell in favor of log4net, as it IMHO made it easier to use, configure, and easier.
In any case, both libraries will be in order, this is more of a personal justification for this project.

+2
source

I am biased, of course. But do yourself a favor and look at my journal structure . It is much easier to use than in some other environments. 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 something else you need. (For example, I have an example code for logging in to Twitter).

+2
source

Log4net is my favorite. Highly customizable, easy to use.

As for the web service for aggregating the incident report with the log, I ran into the same problem and ended up creating the service myself : bugcollect.com . You can download the log4net file added from the site and see it. The service analyzes the report and compiles a similar report in buckets. You can set up email notifications when a new report, new bucket or new source has been sent. You can also configure the response to the bucket, and this response will be returned to the application when a similar incident occurs, for example, instructing the user to download a newer version. The service has a RESTful interface for sending reports, but free client libraries are available for .Net, Java, log4net and log4j, which are available for download. You can try either a free account with limited capabilities, or enter the BETA promo code for a fully functional trial version.

+1
source

Source: https://habr.com/ru/post/1299621/


All Articles