码迷,mamicode.com
首页 > 其他好文 > 详细

NLog简单例子

时间:2018-04-10 13:25:28      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:图片   short   cep   framework   com   debug   code   deb   tor   

引用

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="NLog" version="4.5.2" targetFramework="net461" />
  <package id="NLog.Config" version="4.5.2" targetFramework="net461" />
  <package id="NLog.Schema" version="4.5.2" targetFramework="net461" />
</packages>

配置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"
      xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
      autoReload="true"
      throwExceptions="false"
      internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log">
  <targets>
    <target name="log_file" xsi:type="File" fileName="${basedir}/logs/${shortdate}.log" layout="${longdate} ${uppercase:${level}} ${message}" />
  </targets>

  <rules>
    <logger name="*" minlevel="Debug"   writeTo="log_file" />
  </rules>
</nlog>

 技术分享图片

测试

    class Program
    {
        private static Logger logger = LogManager.GetCurrentClassLogger();
        static void Main(string[] args)
        {
            logger.Trace("Trace Message");
            logger.Debug("Debug Message");
            logger.Info("Info Message");
            logger.Error("Error Message");   
            logger.Fatal("Fatal Message");
        }
    }

技术分享图片

 

NLog简单例子

标签:图片   short   cep   framework   com   debug   code   deb   tor   

原文地址:https://www.cnblogs.com/lgxlsm/p/8778028.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!