nlog.config文件

 

安装nuget包:

NLog.Web.AspNetCore

Exceptionless.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"
autoReload="true"
internalLogLevel="Info"
internalLogFile="Logs/nlog.log">
<extensions>
<add assembly="Exceptionless.NLog"/>
<add assembly="NLog.Web.AspNetCore"/>
</extensions>
  <targets async="true">

<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="Exceptionless" name="exceptionless" apiKey="修改apiKey"
serverUrl="修改serverUrl">
      <field name="host" layout="${machinename}" />
      <field name="identity" layout="${identity}" />
      <field name="windows-identity" layout="${windows-identity:userName=True:domain=False}" />
      <field name="process" layout="${processname}" />
<!--堆栈信息-->
<field name="StackTrace" layout="${stacktrace}"/>
<!--Message信息-->
<field name="Message" layout="${message}"/>
<field name="LogLevel" layout="${level}"/>
<field name="CreateDate" layout="${date}"/>
<!--物理名称-->
<field name="MachineName" layout="${machinename}" />
<!--线程ID-->
<field name="ThreadId" layout="${threadid}"/>
<!--发生源-->
<field name="CallSite" layout="${callsite}"/>
<field name="AppdomainVersion" layout="${assembly-version}"/>
<field name="Appdomain" layout="${appdomain}"/> 
</target>  
</targets>
<rules>
<logger name="*" minlevel="Trace" maxlevel="Fatal" writeTo="exceptionless" />
<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" />
</rules>
</nlog>

配置文件结束

 

posted on 2021-06-25 09:58  jeffh  阅读(272)  评论(1编辑  收藏  举报