Search code examples
loggingevent-logenterprise-library

Event Log written as Warning instead of Error


I'm using EntLib 4.1 for logging. When I have an exception handled in the Application_Error of Global.asax.cs, I log the error with a category of 'Error'. I assumed that the event log type would be 'Error', but instead the event log entry is written with a type of 'Warning' and category of 'Web Event'.

public static void Write(Exception ex)
{
     var log = new LogEntry
     {
          Message = ex.Message
     };

     Logger.Write(log, "Error");
}

Is there some disconnect between an event log type and log category?

How can I get my web application to log with a type of 'Error' from Enterprise Library?


Solution

  • Try setting up a LogEntry object that looks more like this:

    var log = new LogEntry
    {
        Category = "Exception";
        Severity = Severity.Error;
        Message = message;
    }
    

    http://codebetter.com/blogs/david.hayden/archive/2005/03/17/59974.aspx