15

I have the following log4net configuration:

<log4net>
  <appender name="A1" type="log4net.Appender.RollingFileAppender">
    <file type="log4net.Util.PatternString" value="C:\path1.log" />
  </appender>

  <appender name="A2" type="log4net.Appender.RollingFileAppender">
    <file type="log4net.Util.PatternString" value="C:\path2.log" />
  </appender>

  <logger name="A1Logger">
    <level value="ALL" />
    <appender-ref ref="A1" />
  </logger>

  <logger name="A2Logger">
    <level value="ALL" />
    <appender-ref ref="A2" />
  </logger>

</log4net>

and then in code I do the following:

var logger1 = LogManager.GetLogger("A1Logger");
var logger2 = LogManager.GetLogger("A2Logger");

but both log to the same file C:\path1.log.

What am I doing wrong?

Philipp M
  • 1,877
  • 7
  • 27
  • 38
Román
  • 1,943
  • 2
  • 18
  • 28
  • 1
    I'm not sure what the problem could be. Is there any more configuration you are not showing us? Like is there a "root" logger setup? Are you sure you are logging to logger2 (basically that there isn't a typo)? Does it ever log to path2.log? – Mafu Josh Aug 14 '10 at 01:52
  • Can you please provide a little more information? Are there multiple log4net configuration files in your application or is this the only one? How are you loading this configuration file? Through code or automatically through your assembly properties? Also, is this a standard application or a web app? – gregwhitaker Aug 15 '10 at 16:19
  • Oh, it started again.@gwhitake, I'm using a single configuration file, my app is a desktop app and the only code I'm using is that in the initial post. I also added a element just in case but the bug keeps biting me – Román Sep 08 '10 at 11:14

2 Answers2

3

Add the debug="true" attribute to the <log4net> element, my guess is that it is the missing <root> element that causes problems. You should always include the <root /> logger element.

Peter Lillevold
  • 33,668
  • 7
  • 97
  • 131
1

Seems that it was a weird debugging error. Right now it doesn't reproduce. My apologies.

Román
  • 1,943
  • 2
  • 18
  • 28