R – Event Log written as Warning instead of Error

enterprise-libraryevent-loglogging

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?

Best Answer

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

Related Topic