Question

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?

Was it helpful?

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top