很實用的NLog配置分享
前言
NLog是一個基于.NET平臺編寫的類庫,我們可以使用NLog在應(yīng)用程序中添加極為完善的跟蹤調(diào)試代碼。本文主要介紹的是關(guān)于NLog配置的相關(guān)內(nèi)容,下面話不多說了,來一起看看詳細的介紹吧
NLog配置
新建一個文件命名為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">
<targets>
<target name="asyncFile" xsi:type="AsyncWrapper">
<target name="log_file" xsi:type="File"
fileName="${basedir}/Logs/${shortdate}/${shortdate}.txt"
layout="${longdate} | ${message} ${onexception:${exception:format=message} ${newline} ${stacktrace} ${newline}"
archiveFileName="${basedir}/archives/${shortdate}-{#####}.txt"
archiveAboveSize="102400"
archiveNumbering="Sequence"
concurrentWrites="true"
keepFileOpen="false" />
</target>
<target name="console" xsi:type="ColoredConsole" layout="[${date:format=HH\:mm\:ss}]:${message} ${exception:format=message}" />
</targets>
<rules>
<logger name="*" minlevel="Error" writeTo="asyncFile" />
<logger name="*" minlevel="Debug" writeTo="console" />
</rules>
</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="logLayout"
value="Logger:${logger}${newline}Date:${longdate} Level:${uppercase:${level}}${newline}Message:${message} ${newline}${onexception:Exception:${exception:format=toString}${newline}}" />
<targets>
<target name="asyncFile" xsi:type="AsyncWrapper">
<target name="log_file" xsi:type="File"
fileName="${basedir}/Logs/${shortdate}/${shortdate}.txt"
layout="${logLayout}"
archiveFileName="${basedir}/archives/${shortdate}-{#####}.txt"
archiveAboveSize="102400"
archiveNumbering="Sequence"
concurrentWrites="false"
keepFileOpen="true"
encoding="utf-8"
openFileCacheTimeout="30"/>
</target>
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="asyncFile" />
</rules>
</nlog>
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,謝謝大家對腳本之家的支持。
相關(guān)文章
ASP.NET在IIS上注冊報0x800702e4錯誤解決方法
報一個0x800702e4 請求的操作需要提升的錯誤。解決的方法和前面大同小異,給這個aspnet_regiis.exe創(chuàng)建一個快捷方式,給它的目標(biāo)后面加上 一個-i,再右擊這個快捷方式,以管理員身份運行,就行了2012-08-08
詳解.NET?Core如何構(gòu)建一個彈性的HTTP請求機制
在分布式系統(tǒng)中,服務(wù)間的依賴關(guān)系復(fù)雜,任何一個服務(wù)的故障都可能導(dǎo)致整個系統(tǒng)的不可用,這時彈性?HTTP?請求機制就可以幫助我們,下面我們就來看看.NET?Core如何構(gòu)建一個彈性的HTTP請求機制吧2025-01-01
未處理的事件"PageIndexChanging" 之解決方案
今天我寫一個小程序遇到這個問題,上網(wǎng)搜了一下,已經(jīng)有很好的解決方法了,以前都是拉控件自己生成,現(xiàn)在用代碼自己寫就出現(xiàn)了這個問題2008-07-07
ASP.NET實現(xiàn)從服務(wù)器下載文件問題處理
本文主要介紹了ASP.NET實現(xiàn)從服務(wù)器下載文件問題處理,具有很好的參考價值,下面跟著小編一起來看下吧2017-02-02
創(chuàng)建第一個ASP.NET應(yīng)用程序(第1節(jié))
本文通過創(chuàng)建第一個ASP.NET應(yīng)用程序,了解.net代碼后置技術(shù)以及事件驅(qū)動機制和web頁面設(shè)計中的基本控件使用,具有一定的參考價值,感興趣的小伙伴們可以參考一下2015-08-08

