惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

K
Kaspersky official blog
G
Google Developers Blog
Apple Machine Learning Research
Apple Machine Learning Research
V
Visual Studio Blog
WordPress大学
WordPress大学
博客园 - Franky
雷峰网
雷峰网
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 【当耐特】
人人都是产品经理
人人都是产品经理
月光博客
月光博客
V
V2EX
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
IT之家
IT之家
小众软件
小众软件
Cloudbric
Cloudbric
量子位
N
News and Events Feed by Topic
Vercel News
Vercel News
Security Archives - TechRepublic
Security Archives - TechRepublic
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
Check Point Blog
The Cloudflare Blog
Hugging Face - Blog
Hugging Face - Blog
T
Tenable Blog
S
Secure Thoughts
Know Your Adversary
Know Your Adversary
C
CXSECURITY Database RSS Feed - CXSecurity.com
C
Cyber Attacks, Cyber Crime and Cyber Security
Stack Overflow Blog
Stack Overflow Blog
Help Net Security
Help Net Security
L
LINUX DO - 最新话题
Google DeepMind News
Google DeepMind News
云风的 BLOG
云风的 BLOG
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
N
News | PayPal Newsroom
PCI Perspectives
PCI Perspectives
T
Troy Hunt's Blog
GbyAI
GbyAI
Attack and Defense Labs
Attack and Defense Labs
C
Cybersecurity and Infrastructure Security Agency CISA
Y
Y Combinator Blog
美团技术团队
爱范儿
爱范儿
Martin Fowler
Martin Fowler
Last Week in AI
Last Week in AI
P
Privacy International News Feed
T
The Blog of Author Tim Ferriss
F
Full Disclosure

博客园 - wzc998

Oracle Audit 关于"cannot perform a DDL, commit or rollback inside a query or DML" 错误 关于varchar2在pl/sql和schema级别的最大值 ORA-01031 权限不足错误的解决 通过代码备份存储过程,package body 和表数据 并还原 XSL ASP .net实现松耦合事件的三种方法 SQL*Loader FAQ 【转】NLS 视图的研究 oracle多语言环境下to_date时间转换问题 【转】如何使用 ADO.NET 和 Visual C# .NET 调用带参数的存储过程 【转】SQL SERVER 存储过程学习笔记 【转】代码复用原则:合理使用类组合和类继承 委托与接口的关系 IOC 【转】范式 【转】oracle范式与交叉表 oracle存储过程返回交叉表(使用存储过程/高级语言调用)
Log4net不同版本在app.config和web.config的配置区别
wzc998 · 2011-05-05 · via 博客园 - wzc998

整理一下,以防下次再浪费时间了。

app.config配置方法(Log4net v1.2.0 )

1,app.config中

  <configSections>

    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />

  </configSections>

  <log4net>

    <!-- Define some output appenders -->

。。。 

    <!-- Setup the root category, add the appenders and set the default level -->

。。。 

    <!-- logger instance -->

    <logger name="somename">

。。。

    </logger>

  </log4net> 

2, AssemblyInfo.cs中

[assembly:  log4net.Config.DOMConfigurator(ConfigFileExtension = "config", Watch = true)]

3,定义变量和使用

static ILog log = LogManager.GetLogger("somename")

log.Error("test"); 

 Web.config配置方法(Log4net v1.2.0 )

 1,web.config中(通app.config配置一样)

  <configSections>

    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />

  </configSections>

  <log4net>

    <!-- Define some output appenders -->

。。。 

    <!-- Setup the root category, add the appenders and set the default level -->

。。。 

    <!-- logger instance -->

    <logger name="somename">

。。。

    </logger>

  </log4net> 

2, AssemblyInfo.cs中

[assembly: log4net.Config.DOMConfigurator(new System.IO.FileInfo(System.Web.HttpContext.Current.Server.MapPath("Web.Config ")))]

3,定义变量和使用(通app.config配置一样)

static ILog log = LogManager.GetLogger("somename")

log.Error("test"); 

可见v1.2.0配置比较麻烦 ,下面是v1.2.10的配置方法

 app.config配置方法(Log4net v1.2.10 )

1,app.config中(还是一样)

  <configSections>

    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />

  </configSections>

  <log4net>

    <!-- Define some output appenders -->

。。。 

    <!-- Setup the root category, add the appenders and set the default level -->

。。。 

    <!-- logger instance -->

    <logger name="somename">

。。。

    </logger>

  </log4net> 

2, AssemblyInfo.cs中(可选

[assembly: log4net.Config.XmlConfigurator(ConfigFileExtension = "config", Watch = true)] 

3,定义变量和使用

static ILog log = LogManager.GetLogger("somename")

 log4net.Config.XmlConfigurator.Configure(); --这个执行一次就可以.

log.Error("test");  

注: 2步中的[assembly: log4net.Config.XmlConfigurator(ConfigFileExtension = "config", Watch = true)] 等效于 

3步中的 log4net.Config.XmlConfigurator.Configure();

Web.config配置方法(Log4net v1.2.10 )

 1,web.config中(一样)

  <configSections>

    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />

  </configSections>

  <log4net>

    <!-- Define some output appenders -->

。。。 

    <!-- Setup the root category, add the appenders and set the default level -->

。。。 

    <!-- logger instance -->

    <logger name="somename">

。。。

    </logger>

  </log4net> 

2, AssemblyInfo.cs中 (这步没了)

3,定义变量和使用

static ILog log = LogManager.GetLogger("somename")

log4net.Config.XmlConfigurator.Configure(); --这个执行一次就可以.

log.Error("test");  

 显然v1.2.10引入的 XmlConfigurator增加了配置途径,使webapplication纪日志方便了。

经我测试v1.2.0并不能使用和普通webapplication 相同的配置方式支持wcf. 而v1.2.10新的配置方式使它对wcf依然支持。

给各完整的config配置 

 <configuration>

<configSections> 

<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" /> 

</configSections> 

    <!-- Define some output appenders -->

    <appender name="ProjectLogAppender" type="log4net.Appender.RollingFileAppender">

      <param name="File" value="C:\\ServPMSLog\\SvrPlog.txt"/>

      <param name="AppendToFile" value="true"/>

      <param name="MaxSizeRollBackups" value="10"/>

      <param name="MaximumFileSize" value="10000000"/>

      <param name="RollingStyle" value="Size"/>

      <param name="StaticLogFileName" value="true"/>

      <layout type="log4net.Layout.PatternLayout">

        <param name="Header" value="[Header] "/>

        <param name="Footer" value="[Footer] "/>

        <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n"/>

    <appender name="UserLogAppender" type="log4net.Appender.RollingFileAppender">

      <param name="File" value="C:\\ServPMSLog\\SvrUlog.txt"/>

      <param name="AppendToFile" value="true"/>

      <param name="MaxSizeRollBackups" value="10"/>

      <param name="MaximumFileSize" value="10000000"/>

      <param name="RollingStyle" value="Size"/>

      <param name="StaticLogFileName" value="true"/>

      <layout type="log4net.Layout.PatternLayout">

        <param name="Header" value="[Header] "/>

        <param name="Footer" value="[Footer] "/>

        <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n"/>

    <!-- Setup the root category, add the appenders and set the default level -->

      <appender-ref ref="ProjectLogAppender"/>

    <logger name="ProjectLog">

      <appender-ref ref="ProjectLogAppender" />

      <appender-ref ref="UserLogAppender" />

</log4net> 

</configuration>