1

I've created a scheduler project (console application with quartz.net) that contains several classes (jobs) that will be executed recurrently. I'm using log4Net to create the log files and right now every job is appending it's messages to the same file called scheduler/Scheduler.Info.txt. I would like to have a differente folder for each scheduler job.

what I have now is every job appending on

scheduler/scheduler/scheduler.Info.txt

what I want is:

scheduler/SomeJob1/SomeJobJob1.Info.txt
scheduler/SomeJob2/SomeJobJob2.Info.txt
scheduler/SomeJob3/SomeJobJob3.Info.txt

So, the pattern is

scheduler/{CLASS NAME}/{CLASS NAME}.Info.txt

My current configuration for log4net:

<log4net>
    <root>
      <level value="DEBUG" />
      <appender-ref ref="SchedulerLogFileInfoAppender" />
    </root>

    <appender name="SchedulerLogFileInfoAppender" type="log4net.Appender.RollingFileAppender" >
      <param name="File" value="c:\Scheduler\Scheduler.Info.log" />
      <param name="AppendToFile" value="true" />
      <rollingStyle value="Size" />
      <maxSizeRollBackups value="10" />
      <maximumFileSize value="10MB" />
      <staticLogFileName value="true" />

      <layout type="log4net.Layout.PatternLayout">
        <param name="ConversionPattern" value="%d{dd/MM/yy HH:mm:ss} - %p - %logger - %m%n" />
      </layout>

      <filter type="log4net.Filter.LevelRangeFilter">
        <levelMax value="INFO" />
      </filter>
    </appender>
</log4net>

And this is one of the jobs logging a message:

 public class SomeJob1: IJob
    {
        private static readonly ILog logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

    ...

     private void DoStuff()
     {
         logger.Info("THIS IS A MESSAGE");

         ...
     }
}
Rafael Companhoni
  • 1,780
  • 1
  • 15
  • 31
  • So just to clarify, these are not 3 **named instances** of `SomeJob`, but actually 3 instances of 3 classes, `SomeJob1, SomeJob2, SomeJob3`? – code4life Sep 24 '15 at 19:30
  • 1
    If that is the case, then an answer was already posted: http://stackoverflow.com/questions/2445642/log4net-separate-log-files-for-each-class – code4life Sep 24 '15 at 19:33
  • Yes, but I was hoping there was a 'dynamic' way to do it since we plan to add a lot more jobs to this scheduler – Rafael Companhoni Sep 24 '15 at 19:59

0 Answers0