How do I configure a RollingFileAppender to roll by date and size with log4net?

前端 未结 4 1004
迷失自我
迷失自我 2020-12-15 17:42

I am configure log4net to use a composite RollingFileAppender so that the current file is always named logfile.log and all subsequent files are named

4条回答
  •  温柔的废话
    2020-12-15 18:12

    According to log4net RollingFileAppender source code:

    protected string GetNextOutputFileName(string fileName)
    {
        if (!m_staticLogFileName) 
        {
            fileName = fileName.Trim();
    
            if (m_rollDate)
            {
                fileName = fileName + m_now.ToString(m_datePattern, System.Globalization.DateTimeFormatInfo.InvariantInfo);
            }
    
            if (m_countDirection >= 0) 
            {
                fileName = fileName + '.' + m_curSizeRollBackups;
            }
        }
    
        return fileName;
    }
    

    So I'm guessing it's not possible to generate a log file with the name you need. I think it's something like logfileYYYY-MM-dd.n.log or similar.

提交回复
热议问题