zl程序教程

您现在的位置是:首页 >  工具

当前栏目

Nlog日志出坑合集详解程序员

日志程序员 详解 合集 NLog 出坑
2023-06-13 09:20:02 时间

1.安装NLog.Web.AspNetCore

2.在Startup.cs文件的方法public void Configure(IApplicationBuilder app, IHostingEnvironment env)中,添加下面一行代码:

env.ConfigureNLog( NLog.config );

Nlog默认配置:

 ?xml version="1.0" encoding="utf-8" ? 

 nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 

 variable name="logDirectory" value="${basedir}/Logs" / 

 targets async="true" 

 target name="file" 

 xsi:type="File" 

 layout="${longdate} ${threadid:padding=4} ${level:uppercase=true:padding=5} ${logger:shortName=true} ${message} ${exception:format=tostring}" 

 fileName="${logDirectory}/log.txt" 

 archiveFileName="${logDirectory}/log.{#}.txt" 

 archiveEvery="Day" 

 archiveNumbering="Rolling" 

 maxArchiveFiles="7" 

 concurrentWrites="true" 

 createDirs="true" 

 autoFlush="true" / 

 /targets 

 rules 

 logger name="*" minlevel="Trace" writeTo="file" / 

 /rules 

 /nlog 

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/2385.html

服务器部署程序员系统优化网站设置运维