如何在NLog文件目标中使用会话变量
本文关键字:会话 变量 目标 NLog 文件 | 更新日期: 2023-09-27 18:01:51
我想把每个会话在不同的文件夹:${basedir}/logs/session/2016-08-11.log
但是我没有发现如何在NLog中使用会话变量。配置
<targets>
<target xsi:type="File" name="Example" fileName="${basedir}/logs/${aspnet-session:Variable=Login}/${longdate}.log" layout="${message}" />
</targets>
我不知道是否可能?
. NET 4应该包含NLog。Web NuGet包
ASP。你需要NLog.Web.AspNetCore和以下配置(非核心不需要)
nlog.config:
<extensions>
<!--enable NLog.Web for ASP.NET Core-->
<add assembly="NLog.Web.AspNetCore"/>
</extensions>
In your 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"
},