我想将每个会话放在不同的文件夹中:
${basedir}/logs/session/2016-08-11.log
但我还没有找到如何在NLog.config中使用会话变量,如
<targets>
<target xsi:type="File" name="Example" fileName="${basedir}/logs/${aspnet-session:Variable=Login}/${longdate}.log" layout="${message}" />
</targets>
我不知道它是否可能?有什么想法吗?
答案 0 :(得分:1)
对于ASP.NET 4,您应该包含NLog.Web NuGet包
对于ASP.NET Core,您需要NLog.Web.AspNetCore和以下配置(非核心不需要)
在你的nlog.config中:
<extensions>
<!--enable NLog.Web for ASP.NET Core-->
<add assembly="NLog.Web.AspNetCore"/>
</extensions>
在你的startup.cs
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
//add NLog to ASP.NET Core
loggerFactory.AddNLog();
//add NLog.Web
app.AddNLogWeb();
在project.json中:
"dependencies": {
"NLog.Extensions.Logging": "1.0.0-rtm-alpha4",
"NLog.Web.AspNetCore": "4.2.3"
},