tags:

views:

40

answers:

1

i'm very new to the log4net, and i am trying to create several files and log to them accordingly with my method calls, and . here is my code

 private static readonly ILog firstlog = LogManager.GetLogger("Data"); private static readonly ILog secondlog = LogManager.GetLogger("General");

and then i log like this:

firstlog.Info("some message"); secondlog.Info("some message");

and here is my configuration file

<appender name="General" type="log4net.Appender.RollingFileAppender">
  <file type="log4net.Util.PatternString" value="C:\logs\myfile1.log"/>
  <param name="Threshold" value="DEBUG"/>
  <appendToFile value="true"/>
  <rollingStyle value="Size"/>
  <maxSizeRollBackups value="10"/>
  <maximumFileSize value="10MB"/>
  <staticLogFileName value="true"/>
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date [%thread] %method %-5level %logger – %message%newline"/>
  </layout>
</appender>
<appender name="Data" type="log4net.Appender.RollingFileAppender">
  <file type="log4net.Util.PatternString" value="C:\logs\myfile2.log"/>
  <param name="Threshold" value="DEBUG"/>
  <appendToFile value="true"/>
  <rollingStyle value="Size"/>
  <maxSizeRollBackups value="10"/>
  <maximumFileSize value="10MB"/>
  <staticLogFileName value="true"/>
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date [%thread] %method %-5level %logger – %message%newline"/>
  </layout>
</appender>
<logger name="general">
  <appender-ref ref="General"/>
</logger>
<logger name="data">
  <appender-ref ref="Data"/>
</logger>
<root>
  <appender-ref ref="Data"/>
</root>

And they are all logged in one file and the other 2 files are empty. why is this? What am i doing wrong?

A: 

Try removing the line

 <appender-ref ref="Data"/>

from the node...

Koen
should i remove the root node, and if i remove that from all the loggers wouldn't it be the same logging to single file.
Precious
The <root> node itself should remain in the configuration. In your example, the appender "Data" is configured twice, because each logger inherits the configuration from root. If you empty the root node, you fix that.
Koen
yes it worked when i removed the appender from the root node it stopped it from logging evrything to file2. but there was another internal error that was causing this dilema i had fixed now.thnx by d way...god i love this site very helpful people :P
Precious