开发者

Enterprise Library 5 Logging Block: How to write to event viewer?

开发者 https://www.devze.com 2023-04-06 15:14 出处:网络
I\'m using Logging Application Block from Enterprise Library 5 trying to log into flat file and event log. My configuration looks like this:

I'm using Logging Application Block from Enterprise Library 5 trying to log into flat file and event log. My configuration looks like this:

Enterprise Library 5 Logging Block: How to write to event viewer?

I'm using this code to write to logs:

Logger.Write("message", "General1");
Logger.Write("message", "General2");

The problem is, I get the flat file logging ok, but event log never shows the log entries. I've made there a custom view to filter for "Enterprise Library Logging".

How can one produce entries in the event viewer log with Ent lib 5?

开发者_运维问答

Thanks.

Pom.


I think there are two things that could be happening here:

  1. Logging is working but your custom filter is not correct
  2. Logging is not working

Let's be optimistic and assume that logging is working.

Logging is Working

You've configured the EventLogTraceListener to log to an Event Log called MyLog with a source of "Enterprise Library Logging". Perhaps the custom filter is configured to filter by log and is not searching MyLog? Double check your filter and also check that there actually is a log under Applications and Services Logs called MyLog.

If I were to guess, though, that's probably not the issue.

Logging Is Not Working

Let's assume that logging is not working. The most likely reason that it is not working is that you don't have permission to create an event log. I also notice that the Logging Errors & Warnings section is not configured with a listener. It's always a good idea to setup the Logging Errors & Warnings to use a trace listener (I prefer the flat file trace listener since it's one of the simplest so less can go wrong).
So, in your case, I would set it to use the "Flat File Trace Listener" that you have already set up:

 <specialSources>
   <allEvents switchValue="All" name="All Events" />
   <notProcessed switchValue="All" name="Unprocessed Category" />
   <errors switchValue="All" name="Logging Errors &amp; Warnings">
    <listeners>
     <add name="Flat File Trace Listener" />
    </listeners>
   </errors>
  </specialSources>

Now if you re-run your program you should probably see an error message in the consoletrace.log.

If permissions are the problem the usual solution is to create the event logs and their sources during installation with an account that has the proper permissions. E.g. logging a message as administrator to setup your log and category.


I know this is an older question now, but in order to use the event log, the event source must be created first (by a user having Administrative Privileges). In addition, if you are trying to use this within a web site, the NETWORK SERVICE account must be granted access to write to the event log. This site will help: http://msdn.microsoft.com/en-us/library/ms998320.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消