NLog简单例子
Posted 积少成多
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了NLog简单例子相关的知识,希望对你有一定的参考价值。
引用
<?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简单例子的主要内容,如果未能解决你的问题,请参考以下文章
封装一个基于NLog+NLog.Mongo的日志记录工具类LogUtil