页眉和页脚未来的两倍多在log4net的日志 [英] Header and footer coming two times more in log4net logs

查看:158
本文介绍了页眉和页脚未来的两倍多在log4net的日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是log4net的该科从app.config中

< configSections>     <节名称=log4net的TYPE =log4net.Config.Log4NetConfigurationSectionHandler,log4net的/>    < / configSections>    < log4net的调试=真正的>      <附加目的地名称=LogFileAppenderTYPE =log4net.Appender.FileAppender>       <文件类型=log4net.Util.PatternString值=$ {TMP} \ SRG \日志\ LOG_%ENV {USERNAME} _%日期{年月日} .log文件/>       < appendToFile值=真/>       < BUFFERSIZE值=20/>       < LockingModel TYPE =log4net.Appender.FileAppender + MinimalLock/>       <布局类型=log4net.Layout.PatternLayout>       <头类型=log4net.Util.PatternString值=[记录开始]%换行符/>       <脚型=log4net.Util.PatternString值=[日志完]%换行符/>       < conversionPattern值=%DATE [%用户名] - %消息%换行/>       < /布局>      < /附加器>      <记录器名称=SRGApplicationDebugLog>       <电平值=DEBUG/>       <附加目的地-REF REF =LogFileAppender/>      < /记录器>    < / log4net的>

问题1:我得到的页眉和页脚的两次额外的每当我的应用程序已启动,但我需要避免

  

[记录开始]
     [登录完]
     [记录开始]
     [登录完]
      [记录开始]
     2012年11月8日12:25:03376 [用户名] - 应用程序启动
     [登录完]

问题2:我没有收到来自哪里是在两个空页眉页脚对是未来

  1. 在我创建记录仪象下面这样:

_debugLogger = LogManager.GetLogger(SRGApplicationDebugLog); XmlConfigurator.Configure();

  1. 要使用记录器:

_debugLogger.DebugFormat(的LogMessage);

  1. 在我已明确地在AssemblyInfo.cs中加入这一行的log4net

[总成:XmlConfigurator(表=真)

问:要修复以粗体显示的问题。

解决方案

您不需要

  XmlConfigurator.Configure();
 

如果你有

  [总成:XmlConfigurator(表=真)
 

同时拥有将导致两个头和两个页脚研究。

至于为什么你有三套,也许你正在调用 XmlConfigurator.Configure()键两次。

Below is the Section of log4net from app.config

   <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,     log4net" />
   </configSections>      
   <log4net debug="true">
     <appender name="LogFileAppender" type="log4net.Appender.FileAppender">
      <file type="log4net.Util.PatternString" value="${TMP}\SRG\Logs\Log_%env{USERNAME}_%date{yyyyMMdd}.log" />
      <appendToFile value="true" />
      <bufferSize value="20" />
      <LockingModel type="log4net.Appender.FileAppender+MinimalLock"/>
      <layout type="log4net.Layout.PatternLayout">
      <header type="log4net.Util.PatternString" value="[Log Starts]%newline" />        
      <footer type="log4net.Util.PatternString" value="[Log Ends]%newline" />        
      <conversionPattern value="%date [%username] - %message%newline" />
      </layout>
     </appender>  

     <logger name="SRGApplicationDebugLog">
      <level value="DEBUG" />
      <appender-ref ref="LogFileAppender" />
     </logger>
   </log4net>  

Problem 1: I am getting header and footer two times extra whenever my application is started, but I need to avoid it.

[Log Starts]
[Log Ends]
[Log Starts]
[Log Ends]
[Log Starts]
2012-11-08 12:25:03,376 [username] - Application started
[Log Ends]

Problem 2: I am not getting from where is the two empty header footer pair is coming.

  1. I am creating logger like below:

_debugLogger = LogManager.GetLogger("SRGApplicationDebugLog");    
XmlConfigurator.Configure(); 

  1. To use Logger:

_debugLogger.DebugFormat(logMessage);    

  1. I have added this line explicitly in AssemblyInfo.cs for log4net

[assembly: XmlConfigurator(Watch = true)]    

Question: Want to fix the problems in bold

解决方案

You don't need

 XmlConfigurator.Configure();

if you have

[assembly: XmlConfigurator(Watch = true)]

Having both will result in the two headers and two footers.

As to why you have three sets, perhaps you are calling XmlConfigurator.Configure() twice.

这篇关于页眉和页脚未来的两倍多在log4net的日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆