使用CallSite
渲染器进行记录时,方法名称的结果始终为MoveNext
。这是一个错误,还是我做错了什么?
NLog版本:4.6.0
平台:.NET Core 2
当前的NLog配置(如果相关,则为xml或C#)
<target xsi:type="File" name="ownFile-trace" fileName="logs\${machinename}-trace.log"
layout="${longdate}|${aspnet-request-ip}|${aspnet-User-Identity}|${pad:padding=-5:${uppercase:${level}}}|${assembly-version}|${pad:padding=-3:${threadid}}|${aspnet-mvc-controller}|${callsite:className=True:includeNamespace=False:fileName=False:includeSourcePath=False:methodName=True}|${message}|${exception}"
maxArchiveFiles="14"
archiveFileName="logs\archive\${machinename}-trace.{#}.zip"
archiveNumbering="Date"
archiveEvery="Saturday"
archiveDateFormat="yyyyMMdd"
enableArchiveFileCompression ="true"
/>
初始化:
public class Program
{
private static readonly Logger Logger = NLog.Web.NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();
public static void Main(string[] args)
{
try
{
Logger.Info("init main");
CreateWebHostBuilder(args).Build().Run();
}
catch (Exception e)
{
//NLog: catch setup errors
Logger.Error(e, "Stopped program because of exception");
throw;
}
finally
{
// Ensure to flush and stop internal timers/threads before application-exit (Avoid segmentation fault on Linux)
NLog.LogManager.Shutdown();
}
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.ConfigureLogging(logging =>
{
logging.ClearProviders();
logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace);
})
.UseNLog() // NLog: setup NLog for Dependency injection
.ConfigureAppConfiguration(ConfigConfiguration);
...
当前结果是什么?
2018-08-12 16:44:58.8795|::1||TRACE|8.8.11.0|4 |Home|HomeController.MoveNext|
| 预期的结果是什么?
2018-08-12 16:44:58.8795|::1||TRACE|8.8.11.0|4 |Home|HomeController.Index||
您是否检查了内部日志?没有警告
请发布完整的异常详细信息(消息,堆栈跟踪,内部异常:无
有没有解决方法?否
是否有可以使用的版本?不确定
您可以通过编写单元测试来帮助我们吗?否
答案 0 :(得分:2)
您是否已查看${callsite}
布局渲染器的Wiki页面:
https://github.com/NLog/NLog/wiki/Callsite-layout-renderer
尝试启用以下选项:
例如。
${callsite:className=True:includeNamespace=False:fileName=False:includeSourcePath=False:methodName=True:cleanNamesOfAnonymousDelegates=True:cleanNamesOfAsyncContinuations=True}
NLog ver有待处理的任务。 5.0默认启用这些功能:https://github.com/NLog/NLog/issues/1798(重大更改)