0

I have in my config this appender: appender name="TC3DataLogger" type="Intel.STHI.Device.ContextLog.TC3DataLogger" > <file value="null" /> <lockingModel type="log4net.Appender.FileAppender+MinimalLock" /> <appendToFile value="true" /> <rollingStyle value="Once" /> <maxSizeRollBackups value="10" /> <maximumFileSize value="100MB" /> <datePattern value="-yyyyMMdd-HHmm" /> <layout type="log4net.Layout.PatternLayout"> <header value="Date, CS, FeedbackInput, PWM_Duty_Cycle (Cold='-' Hot='+')&#13;&#10;"/> <conversionPattern value="%date{yyyy-MM-dd HH:mm:ss}, %message%newline" /> </layout> <filter type="log4net.Filter.LoggerMatchFilter"> <acceptOnMatch value="true" /> <LoggerToMatch value="Intel.STHI.Device.ContextLog.TC3DataLogger" /> </filter> <filter type="log4net.Filter.DenyAllFilter" /> </appender>

I need to simultaneously log to multiple files. I create each log file this way:

public void CreateNewLogFile(string FileName)
    {
        IAppender[] appenders = LogManager.GetLogger(TC3Logger.GetType()).Logger.Repository.GetAppenders();

        foreach (TC3DataLogger rfa in appenders.OfType<TC3DataLogger>())
        {
            rfa.File = FileName;
            rfa.MaxFileSize = MaxFileSizeKB;
            //sub system that the configuration for this appender has changed. 
            rfa.ActivateOptions();
            TC3datalogRFA = rfa;
        }
    }

Now every time I create a new log file, all my other loggers, log to this file. How can I simultaneously log to the different files? I tried this:

public void WriteToLog(int CSNum, string Message, string LogfileName)
    {
        if (!TC3LogsDictionary[CSNum].Logging) return;
        TC3LogsDictionary[CSNum].TC3datalogRFA.File = TC3LogsDictionary[CSNum].LogFileName;
        TC3LogsDictionary[CSNum].TC3datalogRFA.ActivateOptions();
        TC3LogsDictionary[CSNum].TC3Logger.Info(CSNum, Message);
    }

But I get new files every time I try to log to the files.

tondre3na
  • 29
  • 3

1 Answers1

0

The ability to log to different files would be a feature of a specific appender. You seem to be using some kind of custom appender and I have no idea whether this appender has that feature. I don't think either of the standard log4net file appenders can do this. You could create your own appender by creating a class that inherits from Log4net.Appender.AppenderSkeleton there is a tutorial here that gives an example of how to do it.

Ben Robinson
  • 21,601
  • 5
  • 62
  • 79