如何配置Common.Logging & NLog
Common.Logging提供了一个抽象的日志接口,可以在运行时指定特定的日志处理类库进行日志处理
NLog是一个基于.NET的开源日志处理类库
1)通过NuGet安装Common.Logging
PM> Install-Package Common.Logging
2)通过NuGet安装Common.Logging.NLog32
PM> Install-Package Common.Logging.NLog32
3)在web.config文件中添加如下配置
<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <sectionGroup name="common"> <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" /> </sectionGroup> </configSections> </configuration> <common> <logging> <factoryAdapter type="Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog32"> <arg key="configType" value="INLINE" /> </factoryAdapter> </logging> </common> <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" throwExceptions="true" autoReload="true"> <targets> <target name="debugger" xsi:type="Debugger" layout="${logger}::${message}" /> </targets> <rules> <logger name="*" writeTo="debugger" /> </rules> </nlog>