Click here to Skip to main content
15,881,172 members
Articles / Logging

How To Make Exception Reporting in log4net Awesome

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
15 Oct 2014LGPL3 10.1K   7   3
How to make exception reporting in log4net awesome

Are you using log4net in an existing application and feel that you got no control over your errors? We’ve now created a seamless log4net integration. That means that we will automatically report all exceptions that you are logging.

Problem

In legacy applications, you typically have services that handle business logic like the one below, where all exceptions are logged.

C#
public class SomeService
{
    private ILog _logger = LogManager.GetLogger(typeof (SomeService));

    public void DoSomeStuff()
    {
        try
        {
            //[...]
        }
        catch (Exception ex)
        {
            _logger.Error("Failed", ex);
        }
    }
}

The problem with that are that the errors are drowning in all other log noise. Until now, it has been hard to address that without having to rewrite all those log statements.

Solution

With our solution, you just have to add two lines of code to inject OneTrueError into the log4net pipeline:

C#
class Program
{
    static void Main(string[] args)
    {
        XmlConfigurator.Configure(new FileInfo("log4net.config"));
        OneTrue.Configuration.Credentials("99948f8a-545d-491b-8dff-4fef6c250110",
                                            "c742290e-a80d-4ecb-8065-338780b61b2a");

        // injects into the log4net pipeline
        OneTrue.Configuration.CatchLog4NetExceptions();
            
        //the rest of your app initialization
    }
}

(You need to install our “onetrueerror.log4net” nuget package first.)

With that, you got all our features including the dead easy email notifications:

Signup at OneTrueError today! It’s free.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


Written By
Founder 1TCompany AB
Sweden Sweden

Comments and Discussions

 
QuestionImage broken Pin
rht34115-Oct-14 2:00
rht34115-Oct-14 2:00 
AnswerRe: Image broken Pin
jgauffin15-Oct-14 2:16
jgauffin15-Oct-14 2:16 
GeneralRe: Image broken Pin
rht34115-Oct-14 2:21
rht34115-Oct-14 2:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.