log4net property

  • 161
  • 0

log4net property

   

  public MainForm()
        {
            log4net.GlobalContext.Properties["DeviceID"] = "susu";
            log4net.ILog logger = log4net.LogManager.GetLogger(typeof(Program));
            log4net.Config.XmlConfigurator.Configure();//記得要有這個
            logger.Info("Inside OnDataAvailable");

        
        }



 <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
      <file type="log4net.Util.PatternString" value="LogFiles\default_%property{DeviceID}.log"/>
      <staticLogFileName value="true" />
      <appendToFile value="true" />
      <rollingStyle value="Date" />
      <datePattern value="yyyyMMdd.lo\g" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level - %message%newline" />
      </layout>
    </appender>