Event Log write always logging as an error

Topics: Logging Application Block
Oct 1, 2010 at 9:23 AM

Hi,

I'm using the Logging application block and want to write errors in all my error handlers but also in some instances I want to write either information or warning.

Despite what I set as the TraceEventType.Warning.  Is this the wrong place to set this? what am I doing wrong?

 

Oct 1, 2010 at 9:34 AM
Edited Oct 1, 2010 at 9:37 AM

Could you exactly describe what is the problem?  If you set the log's severity to TraceEventType.Warning, is it being logged or not?  What is the value of the Filter property of your Event Log Trace Listener?  Keep in mind that the Filter property of trace listeners means allow this and everything else important.  So if you set it to Error, it will log errors and critical messages.   

Sarah Urmeneta
Global Technology and Solution
Avanade, Inc.
entlib.support@avanade.com

Oct 1, 2010 at 12:45 PM

Hi it's always logging but always logs it as an error despite what I set as the TraceEventType.  All the filters are set to allow all but I'd like them to appear in the Event log as Warnings when I specify warnings rather than every log entry appearing as an error.

Oct 1, 2010 at 1:08 PM

Are you sure the logs you're getting in the event log are the exact log you're writing? Because it's possible that those are logs generated as a result of exception while logging.

Still, I doubled check and created a LogEntry object specifying its Severity property to TraceEventType.Warning.   I wasn't able to repro your case, it was logged as a warning message in the event log.  Could you post your exact code and the relevant configuration.  Or you could send a small repro in entlib.support@avanade.com

 

Sarah Urmeneta
Global Technology and Solution
Avanade, Inc.
entlib.support@avanade.com

Oct 1, 2010 at 2:27 PM

Have sent email please let me know if you don't get it I've attached the event log also.

Cheers

Oct 1, 2010 at 2:38 PM

Got your email.  As I suspected, the log you're seeing in the event log is due to an exception which occured while logging.  Check again the log in the Event Viewer, the message should be like "There is no explicit mapping for the categories 'Warning'....".  This is because the line

LogEntry log = new LogEntry(exs.Message, "Warning", 1, 101, TraceEventType.Information, "Security Exception", null);

means that you want this log  to be processed by the trace listener(s) under the "Warning" category and it is has a severity equal to TraceEventType.Information.

In your config, you didn't have a "Warning" category.  You only have a "General" category.  So the solution to this is change Warning to General or change the name of your General category to Warning.

 

Sarah Urmeneta
Global Technology and Solution
Avanade, Inc.
entlib.support@avanade.com