Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

log4net / EventLogAppender is ignoring my LogName

Tags:

c#

log4net

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.

like image 281
LinusK Avatar asked Sep 30 '11 07:09

LinusK


2 Answers

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.

like image 152
LinusK Avatar answered Sep 28 '22 08:09

LinusK


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.

like image 29
deadlydog Avatar answered Sep 28 '22 07:09

deadlydog