views:

139

answers:

2

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?

+2  A: 

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

Robert Harvey
Do you need the public?
Preet Sangha
Nope, sorry. It was a partial cut-and-paste from another page.
Robert Harvey
A: 

My first problem was that the configuration was using an old Enterprise Library configuration format and was causing the Warning / Web Event.

The next problem was the default event source was using "Enterprise Library Logging" in the Application event log, which was not defined.

I created a custom source using Powershell and updated my Trace Listener to use that source.

$x = "YourApplicationNameHere"
$source = new-object System.Diagnostics.EventSourceCreationData $x, "Application"
$source .MachineName = gc env:computername
[System.Diagnostics.EventLog]::CreateEventSource($source)

Finally, I was able to set the severity (not category or priority, as I had tried before) as Robert Harvey stated.

Even Mien