10

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.

Philipp M
  • 1,877
  • 7
  • 27
  • 38
LinusK
  • 709
  • 1
  • 5
  • 17

4 Answers4

11

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.

LinusK
  • 709
  • 1
  • 5
  • 17
5

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.

Community
  • 1
  • 1
deadlydog
  • 22,611
  • 14
  • 112
  • 118
1

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!

Arie
  • 5,251
  • 2
  • 33
  • 54
  • It doesn't work :(. I tried it before and tried it again: if (!EventLog.SourceExists("MyApp")) EventLog.CreateEventSource("MyApp", "MyLog"); – LinusK Sep 30 '11 at 09:15
  • 1
    Because the source named "MyApp" probably already exists on your computer after you installed your application and the program doesn't go into "if" statement (insert braekpoint there and check). The source is created during install and automaticaly assigned to Application log. Check using windows event viewer (I usually select custom views, create new, by event source, and if my source is on the drop down list, it means it exists) or check registry. So if it exists you need to delete it first, and then create it, or just create event source with different name. – Arie Sep 30 '11 at 14:13
-1

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

Vitaly Zemlyansky
  • 331
  • 1
  • 3
  • 12
  • 1
    -, this is just another notation (just a cosmetic issue), the result of the param won't change –  Jan 12 '12 at 09:04
  • @AndreasNiedermair, It might be cosmetic in some cases, but I'm running into an issue where it appears to make a difference. In my case `` has an extra requirement, that the main application assembly name has to be equal to the specified value in order to get entries to be written (the eventlog itself is being created thogh). Using the `` notation, events are being written even thogh the assembly name does not match. – Louis Somers Feb 27 '14 at 10:43
  • good catch! could you maybe provide an example in your answer, so that the use-case gets clearer..? –  Feb 27 '14 at 10:54