很實用的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)容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對腳本之家的支持。
相關(guān)文章
ASPX向ASCX傳值以及文本創(chuàng)建圖片(附源碼)
把用戶在TextBox輸入的文字創(chuàng)建為一個圖片,ASCX的ImageButton的ImageUrl重新指向這剛產(chǎn)生的圖片,接下來介紹下ASPX向ASCX傳值,感興趣的朋友可以參考下哈2013-03-03
asp.net中SqlCacheDependency緩存技術(shù)概述
這篇文章主要介紹了asp.net中SqlCacheDependency緩存技術(shù)概述,是大型web程序設(shè)計中常用的技術(shù),本文對此進行了較為詳細的描述,需要的朋友可以參考下2014-08-08
基于Asp.Net MVC4 Bundle捆綁壓縮技術(shù)的介紹
本篇文章,小編將為大家介紹,Asp.Net MVC4 Bundle捆綁壓縮技術(shù),有需要的朋友可以參考一下2013-04-04
asp.net Request.ServerVariables[] 讀解
asp.net Request.ServerVariables[] 讀解,學習.net的朋友可以參考下,方便獲取服務(wù)器的一些信息。2011-08-08

