Is it possible to use the ${shortdate} in the internalLogFile?

百般思念 提交于 2019-12-10 17:52:03

问题


Is it possible to use the ${shortdate} in the internalLogFile?

<nlog internalLogFile="C:\Logs\${shortdate}_nlog.log"
    <targets>
        <target name="logfile"
                fileName="C:/logs/${shortdate}_dev.log"
        </target>

I'm getting the expected dated logfile, but the internal log file is named ... ${shortdate}_nlog.log


回答1:


Short answer: No.

Longer answer: The internal logger file name is just a string. It's read in during initialization and the XmlLoggingConfiguration class ensures that the directory exists whereas (for example) the FileTarget uses a Layout for fileName that converts the value provided using LayoutRenderers.




回答2:


https://github.com/NLog/NLog/issues/581#issuecomment-74923718

My understanding from reading their comments is that the internal logging should be simple, stable, and used sparingly. Typically you are only supposed to turn it on when trying to figure out whats going wrong with your setup.

You can still dynamically name your internal log file based on the date time if you want. However it won't have the same rollover effect a target file would. It would essentially have a different datetime whenever you initialized your logger I think.

DateTime dt = DateTime.Now;                
NLog.Common.InternalLogger.LogFile = @"C:\CustomLogs\NLog_Internal\internal_NLogs" + dt.ToString("yyyy-MM-dd") + ".txt";


来源:https://stackoverflow.com/questions/34062182/is-it-possible-to-use-the-shortdate-in-the-internallogfile

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!