1.摘要

Common.Logging定义了一种接口的公共接口,尤其在Quartz.net中作为接口型的组件,而具体则使用log4net,nlog等组件。

2.使用步骤

Install-Package Common.Logging

安装公共日志组件

Install-Package log4net

安装log4net

Install-Package Common.Logging.Log4Net1211

安log4net对Common.Logging的适配库

3.配置文件

注意加粗部分

  1. <?xml version="1.0"?>
  2. <configuration>
  3.   <configSections>
  4.     <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
  5.     <sectionGroup name="common">
  6.       <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging"/>
  7.     </sectionGroup>
  8.   </configSections>
  9.   <common>
  10.     <logging>
  11.       <factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net1211">
  12.         <arg key="configType" value="INLINE"/>
  13.       </factoryAdapter>
  14.     </logging>
  15.   </common>
  16.   <log4net>
  17.     <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
  18.       <layout type="log4net.Layout.PatternLayout">
  19.         <conversionPattern value="%d [%t] %-5p %l - %m%n"/>
  20.       </layout>
  21.     </appender>
  22.     <appender name="EventLogAppender" type="log4net.Appender.EventLogAppender">
  23.       <layout type="log4net.Layout.PatternLayout">
  24.         <conversionPattern value="%d [%t] %-5p %l - %m%n"/>
  25.       </layout>
  26.     </appender>
  27.     <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
  28.       <param name="File" value="Log/" />
  29.       <!--<datePattern value="yyyyMMdd&quot;.txt&quot;" />-->
  30.       <appendToFile value="true"/>
  31.  
  32.       <!--Make the rolling file name with the date and size-->
  33.       <rollingStyle value="Composite"/>
  34.       <datePattern value="yyyy-MM-dd&quot;.txt&quot;"/>
  35.       <maxSizeRollBackups value="100"/>
  36.       <maximumFileSize value="2MB"/>
  37.  
  38.       <PreserveLogFileNameExtension value="true"/>
  39.       <staticLogFileName value="false"/>
  40.       <layout type="log4net.Layout.PatternLayout">
  41.         <param name="ConversionPattern" value="%d %-5p %m%n"/>
  42.       </layout>
  43.     </appender>
  44.     <root>
  45.       <level value="DEBUG"/>
  46.       <appender-ref ref="ConsoleAppender"/>
  47.       <appender-ref ref="RollingFileAppender"/>
  48.     </root>
  49.   </log4net>
  50.   <runtime>
  51.     <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  52.       <dependentAssembly>
  53.         <assemblyIdentity name="Common.Logging.Core" publicKeyToken="af08829b84f0328e" culture="neutral"/>
  54.         <bindingRedirect oldVersion="0.0.0.0-3.1.0.0" newVersion="3.1.0.0"/>
  55.       </dependentAssembly>
  56.       <dependentAssembly>
  57.         <assemblyIdentity name="Common.Logging" publicKeyToken="af08829b84f0328e" culture="neutral"/>
  58.         <bindingRedirect oldVersion="0.0.0.0-3.1.0.0" newVersion="3.1.0.0"/>
  59.       </dependentAssembly>
  60.     </assemblyBinding>
  61.   </runtime>
  62. </configuration>

4.样例代码

using Common.Logging;

。。。。。。

ILog log = LogManager.GetLogger(type);

if (log.IsDebugEnabled)

{

string strText = GetMessage("DEBUG", className, methodName, message);

log.Debug(strText);

}

。。。。。。

参考:http://www.tuicool.com/articles/JvIbM3

Comon.Logging与Log4net联合使用的更多相关文章

  1. Logging with Log4net (二)

    log4net 是.net 的一款日志记录框架. 它提供了很多的方法来帮助记录日志: 使用起来也比较方便: 选中项目,点击右键,然后选择 Manage NuGet Packages... 安装log4 ...

  2. 使用Common.Logging与log4net的组件版本兼容问题

    引用:  http://www.cnblogs.com/shijun/p/3713830.html 近期使用了Common.Logging的ILog接口做日志接口,同时利用其log4net适配器与lo ...

  3. Common.Logging log4net Common.Logging.Log4Net 配置

    1.log4net 单独配置 log4net支持多种格式的日志输出,我这里只配置输出到本地的txt文件这种格式. <log4net> <root> <appender-r ...

  4. 使用Common.Logging+log4net规范日志管理

    Common.Logging+(log4net/NLog/) common logging是一个通用日志接口,log4net是一个强大的具体实现,也可以用其它不同的实现,如EntLib的日志.NLog ...

  5. 使用Common.Logging+log4net规范日志管理【转载】

    使用Common.Logging+log4net规范日志管理   Common.Logging+(log4net/NLog/) common logging是一个通用日志接口,log4net是一个强大 ...

  6. Logging from multiple processes using log4net

    When logging with log4net to a file (using the FileAppender), the FileAppender is holding an exclusi ...

  7. 微软日志工厂 Microsoft.Extensions.Logging 中增加 log4net 的日志输出

    前提: 需要nuget   Microsoft.Extensions.Logging.Log4Net.AspNetCore   2.2.6: 描述:解决 .net core 微软日志工厂 Micros ...

  8. 基于Common.Logging + Log4Net实现的日志管理

    前言 Common.Logging 是Commons-Logging(apache最早提供的日志门面接口,提供了简单的日志实现以及日志解耦功能) 项目的.net版本.其目的是为 "所有的.n ...

  9. Log4net 日志使用介绍

    概述 Log4net 有三个主要组件:loggers,appenders 和 layouts.这三个组件一起工作使得开发者能够根据信息类型和等级(Level)记录信息,以及在运行时控制信息的格式化和信 ...

随机推荐

  1. 注意页面上的时间戳可能会成为bd快照的时间_快照不更新的原因

    之前在创建内容的时候,为了提高说服力,添加了一个原始文章的地址**.com.cn/2013-08/22/content_**.htm,当时写文章是在12月份,单快照直接变成原始文章的时间戳8.22

  2. Windows主机里利用VMware安装Linux(CentOS)虚拟机,Host-only连接上网方式详解

    关于Host-only指的是主机与虚拟机之间的互联,因此虚拟机是不能连网的,若需要连网则需要使用NAT模式: Host-only模式实现联网得考虑如下配置过程: 附:VMware虚拟机三种网络模式(B ...

  3. NGUI例子Scroll View场景中item添加点击后自动滑到终点

    http://blog.csdn.net/luyuncsd123/article/details/22914497 最近在做一个项目的UI,需求是1.拖动items后当永远有一个item保存在中间位置 ...

  4. UNITY3D与iOS交互解决方案

    原地址:http://bbs.18183.com/thread-456979-1-1.html 本帖最后由 啊,将进酒 于 2014-2-27 11:17 编辑 “授人以鱼,不如授人以渔”,以UNIT ...

  5. Tomcat打包时多项目共享jar和精确指定jar版本

    在产品打包发布时一个tomcat中如果存在多个war,部署的一般方式是部署到%TOMCAT_HOME%/webapps目录下,目录结构遵循J2EE规范,把引用的jar放到%TOMCAT_HOME%/w ...

  6. python4delphi 设置syspath

    详细看demo25的代码 These techniques are demonstrated in Demo25 in the examples folder of your Python for D ...

  7. delphi 2007 远程调试

    Remote debugging lets you debug a RAD Studio application running on a remote computer. Once the remo ...

  8. python 最佳入门实践

    勿在浮沙筑高台,无论什么技术,掌握核心精神和api,是很重要的. 但是入门过程也可能不是一帆风顺的,这里有八个入门任务,看看你完成了没有: http://code.tutsplus.com/artic ...

  9. Easy Multiple Copy to Clipboard by ZeroClipboard

    要实现在多个复制按钮复制的功能(具体代码在附件中,路径修改一下就行了): <%@ page language="java" import="java.util.*& ...

  10. css3 变形(transform)、转换(transition)和动画(animation)

    http://www.w3cplus.com/content/css3-transform/  在CSS3中transform主要包括以下几种:旋转rotate.扭曲skew.缩放scale和移动tr ...