开发者

log4net / EventLogAppender is ignoring my LogName

开发者_Python百科This configuration should make my log entries end up in a custom log, right? But it ends up in the Application log. My app is running as admin. After I run my app I can confirm that the Log and event source is created by using EventLog.Exists("MyLog") and EventLog.SourceExists("MyApplication").

<appender name="EventLogAppender" type="log4net.Appender.EventLogAppender" >
  <logName value="MyLog"/>
  <applicationName value="MyApp" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date [%thread] %-5level %logger - %message %exception%newline" />
  </layout>
</appender>

Edit: I found out what the problem was but I can't "self-answer" my question until 8h has passed.


I found out the problem.

  1. Refresh in Event View does not show new logs. I had to restart the Event Viewer to see my custom logs that I had managed to create.

  2. Most of my log entries did end up in the Application log although I specified a log name. My conclusion is that I probably at some time early today wrote to the log using the same source name but without a log name so that it "stuck". Modifying the source name and starting over fixed the problem.


I was having the same problem where log4net created my new log, but messages kept getting logged in the Application log. Restarting the Event Viewer did not work, but as per this answer, simply restarting my computer fixed the problem and messages started getting logged to the new log as expected.


Aaah, eventlogs, I so hate them...

Is your app's event source registered within your log? Unless it is, everything you write with it will end up in the Application log. You have to register it during installation or manually, using System.Diagnostics.EventLog.CreateEventSource() (e.g. this one http://msdn.microsoft.com/en-us/library/2awhba7a.aspx)

Beware of naming issues!


Try to use <param name="LogName" value="MyLog" /> instead <logName value="MyLog"/>

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜