Nlog longdate总是返回默认值
本文关键字:返回 默认值 longdate Nlog | 更新日期: 2023-09-27 18:11:06
我有以下NLog目标标签(它都在一行上,为了方便阅读,我只是在这里分开):
<target
name="FileLogger"
xsi:type="File"
fileName="e:'logs'${date:format=yyMMdd}_debug.log"
archiveNumbering="Sequence"
archiveAboveSize="1000000"
layout="${longdate} | ${level:uppercase=true} | ${event-context:item=workName} | ${logger} | ${callsite:filename=true} | ${message}"
archiveEvery="Day"/>
当我查看我的文件夹时,我的日志命名为:
010101_debug.log
010101_debug.0.log
010101_debug.1.log
etc.
那么为什么日期总是010101呢?布局中的${longdate}
也不起作用。如果你还需要我的代码,请告诉我
我解决了!
我在helper类中创建了自己的函数,如下所示:public static void Error(string workName, string message, string logcontext, string exMessage = "")
{
LogEventInfo logEvent = new LogEventInfo(LogLevel.Error, logcontext, message + (!string.IsNullOrEmpty(exMessage) ? ": " : string.Empty) + exMessage);
logEvent.Properties["workName"] = workName;
logger.Log(typeof(InternalLogger), logEvent);
}
对于所有日志级别都是一样的。我不知道为什么,但这解决了它^^