发布时间:2020-07-02 17:02:18来源:本站阅读(965)
首先是引包
NLog.Web.AspNetCore
添加配置文件 nlog.config
<?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" autoReload="true" internalLogLevel="Info">
<!-- 启用.net core的核心布局渲染器 -->
<extensions>
<add assembly="NLog.Web.AspNetCore" />
</extensions>
<!-- 写入日志的目标配置 -->
<targets>
<!-- 调试 -->
<target xsi:type="File" name="debug" fileName="logs/debug-${shortdate}.log" layout="${longdate}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}|url: ${aspnet-request-url}|action: ${aspnet-mvc-action}" />
<!-- 警告 -->
<target xsi:type="File" name="warn" fileName="logs/warn-${shortdate}.log" layout="[${uppercase:${level}}] ${longdate} ${logger} action: ${aspnet-mvc-action} CustomMsg:${message} Exception:${exception:format=tostring} url: ${aspnet-request-url}" />
<!-- 错误 -->
<target xsi:type="File" name="error" fileName="logs/error-${shortdate}.log" layout="${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}|url: ${aspnet-request-url}|action: ${aspnet-mvc-action}" />
</targets>
<!-- 映射规则 -->
<rules>
<!-- 调试 -->
<logger name="*" minlevel="Trace" maxlevel="Debug" writeTo="debug" />
<!--跳过不重要的微软日志-->
<logger name="Microsoft.*" maxlevel="Info" final="true" />
<!-- 警告 -->
<logger name="*" minlevel="Info" maxlevel="Warn" writeTo="warn" />
<!-- 错误 -->
<logger name="*" minlevel="Error" maxlevel="Fatal" writeTo="error" />
</rules>
</nlog>
最后在program里启用NLog
关键字: NLog
上一篇: 重载和重写
1318
1460
1650
1731
3269
4274
856
1445
1428
1313
9593
5996
5523
5116
4567
4274
3415
3336
3335
3269