logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cyz <zhoup...@micron.com>
Subject how to log to different files?
Date Tue, 25 Jan 2011 09:02:11 GMT

Hi, I'm using below configuration, which defines two appenders to log to two
different files. However, I couldn't control which file to log to. i.e. I
thought code below only writes to log.log file, but it's not. It write to
both log.log and rolling.log file. Is there something wrong with the
configuration/code? Many thanks.

----------------------------
//code
log4net.ILog log = log4net.LogManager.GetLogger("RollingFileAppender1");
log.Info("testing");


----------------------------
//configuration
<?xml version="1.0" encoding="utf-8" ?>
<!-- 
		.NET application configuration file     
		This file must have the exact same name as your application with .config
appended to it. 
		
    
		For example if your application is ConsoleApp.exe then the config file
must be ConsoleApp.exe.config. 
		It must also be in the same directory as the application. 
	-->
<configuration>
  <!-- Register a section handler for the log4net section -->
  <configSections>
    <section name="log4net"
type="System.Configuration.Log4NetConfigurationSectionHandler, log4net"/>
  </configSections>
  <!-- This section contains the log4net configuration settings -->
  <log4net>
    <appender name="RollingFileAppender1"
type="log4net.Appender.RollingFileAppender">
      <file value="log.log" />
      <appendToFile value="true" />
      <rollingStyle value="Size" />
      <maxSizeRollBackups value="-1" />
      <maximumFileSize value="1MB" />
      <staticLogFileName value="false" />
      <countDirection value="0" />
      <datePattern value="_yyMMddHHmmss" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%n%d{yyyy-MM-dd hh:mm:ss.fff},%-5level,%m"
/>
      </layout>
    </appender>
    <appender name="RollingFileAppender2"
type="log4net.Appender.RollingFileAppender">
      <file value="rolling.log" />
      <appendToFile value="true" />
      <rollingStyle value="Size" />
      <maxSizeRollBackups value="-1" />
      <maximumFileSize value="1MB" />
      <staticLogFileName value="false" />
      <countDirection value="0" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%n%d{yyyy-MM-dd hh:mm:ss.fff},%-5level,%m"
/>
      </layout>
    </appender>
    <!-- Setup the root category, add the appenders and set the default
level -->
    <root>
      <level value="ALL" />
      <appender-ref ref="RollingFileAppender1" />
      <appender-ref ref="RollingFileAppender2" />
    </root>
  </log4net>
</configuration>
-- 
View this message in context: http://old.nabble.com/how-to-log-to-different-files--tp30748320p30748320.html
Sent from the Log4net - Users mailing list archive at Nabble.com.


Mime
View raw message