很实用的NLog配置分享

所属分类: 网络编程 / ASP.NET 阅读数: 769
收藏 0 赞 0 分享

前言

NLog是一个基于.NET平台编写的类库,我们可以使用NLog在应用程序中添加极为完善的跟踪调试代码。本文主要介绍的是关于NLog配置的相关内容,下面话不多说了,来一起看看详细的介绍吧

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>

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对脚本之家的支持。

更多精彩内容其他人还在看

Asp.net图片上传实现预览效果的简单代码

这篇文章介绍了Asp.net图片上传实现预览效果的简单代码,有需要的朋友可以参考一下
收藏 0 赞 0 分享

ASP.NET动态设置页面标题的方法详解

这篇文章介绍了ASP.NET动态设置页面标题的方法详解,有需要的朋友可以参考一下
收藏 0 赞 0 分享

ASP.NET中获取URL重写前的原始地址详解

在ASP.NET中,如果你使用了URL重写,通过HttpContext.Request获取到的是重写后的地址。如果这个地址要返回给客户端(比如Redirect),我们一般希望是重写前的友好地址。
收藏 0 赞 0 分享

.Net实现合并文件的具体方法

这篇文章介绍了.Net实现合并文件的具体方法,有需要的朋友可以参考一下
收藏 0 赞 0 分享

asp.net 初始化文本框的小例子

这篇文章介绍了asp.net 初始化文本框的小例子,有需要的朋友可以参考一下,希望对你有所帮助
收藏 0 赞 0 分享

用WPF实现屏幕文字提示的实现方法

本文介绍WPF应用程序实现在屏幕上显示一行或多行文字通知。它没有标题栏和最大化最小化等按钮,可以有半透明背景以使文字的显示更清晰,鼠标点击后提示消失。
收藏 0 赞 0 分享

.NET更新Xml中CDATA内容的方法实例

这篇文章介绍了.NET更新Xml中CDATA内容的方法实例,有需要的朋友可以参考一下
收藏 0 赞 0 分享

.NET中弹出对话框的方法汇总

下面是本人对常用对话框使用的汇总,希望对大家有所帮助,同时也欢迎大家补充。
收藏 0 赞 0 分享

ASP.NET动态生成静态页面的实例代码

生成静态页有很多好处,可以缓解服务器压力、方便搜索网站搜索等等,下面介绍一下生成静态页的实例代码,有需要的朋友可以参考一下
收藏 0 赞 0 分享

利用.net控件实现下拉导航菜单制作的具体方法

这篇文章介绍了利用.net控件实现下拉导航菜单制作的具体方法,有需要的朋友可以参考一下,希望对你有所帮助
收藏 0 赞 0 分享
查看更多