nlog.config文件

 

安装nuget包:

NLog.Web.AspNetCore

 

配置开始

<?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"
internalLogFile="Logs/nlog.log" >

<!-- enable asp.net core layout renderers -->
<extensions>
<add assembly="NLog.Web.AspNetCore"/>
</extensions>

<!-- optional, add some variabeles
https://github.com/nlog/NLog/wiki/Configuration-file#variables
-->
<!--<variable name="myvar" value="myvalue"/>-->

<!--
See https://github.com/nlog/nlog/wiki/Configuration-file
for information on customizing logging rules and outputs.
-->

<targets async="true">

<!--
add your targets here
See https://github.com/nlog/NLog/wiki/Targets for possible targets.
See https://github.com/nlog/NLog/wiki/Layout-Renderers for the possible layout renderers.
-->

<!--Writing events to the a file with the date in the filename.-->
<target xsi:type="File" name="errorLogFileTarget" fileName="${basedir}/Logs/nlogs/errors/${shortdate}.log"
layout="${longdate} ${logger} ${uppercase:${level}} ${message} ${newline} ${exception:format=ToString}" />
<target xsi:type="File" name="infoLogFileTarget" fileName="${basedir}/Logs/nlogs/infos/${shortdate}.log"
layout="${longdate} ${logger} ${uppercase:${level}} ${message}" />
<target xsi:type="File" name="debugLogFileTarget" fileName="${basedir}/Logs/nlogs/debugs/${shortdate}.log"
layout="${longdate} ${logger} ${uppercase:${level}} ${message}" />
<target xsi:type="File" name="warnLogFileTarget" fileName="${basedir}/Logs/nlogs/warns/${shortdate}.log"
layout="${longdate} ${logger} ${uppercase:${level}} ${message}" />
<target xsi:type="File" name="fatalLogFileTarget" fileName="${basedir}/Logs/nlogs/fatals/${shortdate}.log"
layout="${longdate} ${logger} ${uppercase:${level}} ${message}" />
<target xsi:type="File" name="traceLogFileTarget" fileName="${basedir}/Logs/nlogs/traces/${shortdate}.log"
layout="${longdate} ${logger} ${uppercase:${level}} ${message}" />

<target xsi:type="Mail" name="errorMailTarget"
smtpServer="smtp.exmail.qq.com"
smtpAuthentication="Basic"
smtpPassword=""
smtpUserName=""
enableSsl="true"
addNewLines="true"
from=""
to=""
subject="Api Error"
header="============================ Api Error Begin ============================="
body="${longdate} ${logger} ${uppercase:${level}} ${message} ${newline} ${exception:format=ToString}"
footer="============================ Api Error End ============================="
/>

</targets>

<rules>
<!-- add your logging rules here -->
<!--Write all events with minimal level of Trace-->
<logger name="*" minlevel="Debug" maxlevel="Debug" writeTo="debugLogFileTarget" />
<logger name="*" minlevel="Info" maxlevel="Info" writeTo="infoLogFileTarget" />
<logger name="*" minlevel="Warn" maxlevel="Warn" writeTo="warnLogFileTarget" />
<logger name="*" minlevel="Error" maxlevel="Error" writeTo="errorLogFileTarget" />
<logger name="*" minlevel="Fatal" maxlevel="Fatal" writeTo="fatalLogFileTarget" />
<logger name="*" minlevel="Trace" maxlevel="Trace" writeTo="traceLogFileTarget" />
<!--<logger name="*" minlevel="Error" maxlevel="Error" writeTo="errorMailTarget" />-->
</rules>
</nlog>

配置结束

posted on 2021-06-25 10:01  jeffh  阅读(281)  评论(0编辑  收藏  举报