<legend id='02wfv'><style id='02wfv'><dir id='02wfv'><q id='02wfv'></q></dir></style></legend>
  • <tfoot id='02wfv'></tfoot>

    <small id='02wfv'></small><noframes id='02wfv'>

  • <i id='02wfv'><tr id='02wfv'><dt id='02wfv'><q id='02wfv'><span id='02wfv'><b id='02wfv'><form id='02wfv'><ins id='02wfv'></ins><ul id='02wfv'></ul><sub id='02wfv'></sub></form><legend id='02wfv'></legend><bdo id='02wfv'><pre id='02wfv'><center id='02wfv'></center></pre></bdo></b><th id='02wfv'></th></span></q></dt></tr></i><div id='02wfv'><tfoot id='02wfv'></tfoot><dl id='02wfv'><fieldset id='02wfv'></fieldset></dl></div>
      <bdo id='02wfv'></bdo><ul id='02wfv'></ul>

      1. log4net 初始化

        log4net initialisation(log4net 初始化)
          <tbody id='rTFTe'></tbody>
          <bdo id='rTFTe'></bdo><ul id='rTFTe'></ul>
          <i id='rTFTe'><tr id='rTFTe'><dt id='rTFTe'><q id='rTFTe'><span id='rTFTe'><b id='rTFTe'><form id='rTFTe'><ins id='rTFTe'></ins><ul id='rTFTe'></ul><sub id='rTFTe'></sub></form><legend id='rTFTe'></legend><bdo id='rTFTe'><pre id='rTFTe'><center id='rTFTe'></center></pre></bdo></b><th id='rTFTe'></th></span></q></dt></tr></i><div id='rTFTe'><tfoot id='rTFTe'></tfoot><dl id='rTFTe'><fieldset id='rTFTe'></fieldset></dl></div>
        • <small id='rTFTe'></small><noframes id='rTFTe'>

            <legend id='rTFTe'><style id='rTFTe'><dir id='rTFTe'><q id='rTFTe'></q></dir></style></legend>

                <tfoot id='rTFTe'></tfoot>

                  本文介绍了log4net 初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我一直在努力寻找重复的内容,但无论看起来多么基本,我都必须提出以下问题,以便一劳永逸地弄清楚!

                  I've looked hard for duplicates but have to ask the following, no matter how basic it may seem, to get it clear once and for all!

                  在 64 位 W7 上的 VS28KSP1 上使用 log4net 版本 1.2.10.0 的全新控制台应用程序中,我有以下代码:-

                  In a fresh Console app using log4net version 1.2.10.0 on VS28KSP1 on 64 bit W7, I have the following code:-

                  using log4net;
                  using log4net.Config;
                  
                  namespace ConsoleApplication1
                  {
                      class Program
                      {
                          static readonly ILog _log = LogManager.GetLogger(typeof(Program));
                          static void Main(string[] args)
                          {
                              _log.Info("Ran");
                          }
                      }
                  }
                  

                  在我的 app.config 中,我有:

                  <?xml version="1.0" encoding="utf-8" ?>
                  <configuration>
                    <configSections>
                      <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
                    </configSections>
                    <log4net>
                      <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
                        <file value="Program.log" />
                        <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
                        <appendToFile value="true" />
                        <rollingStyle value="Size" />
                        <maxSizeRollBackups value="10" />
                        <maximumFileSize value="1MB" />
                        <staticLogFileName value="true" />
                        <layout type="log4net.Layout.PatternLayout">
                          <conversionPattern value="[%username] %date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
                        </layout>
                      </appender>
                  
                      <root>
                        <level value="DEBUG" />
                        <appender-ref ref="RollingFileAppender" />
                      </root>
                    </log4net>
                  
                  </configuration>
                  

                  这不会写任何东西,除非我添加一个属性:

                  This doesnt write anything, unless I either add an attribute:

                  [ assembly:XmlConfigurator ]
                  

                  或者在Main()中显式初始化:

                  Or explicitly initialise it in Main():

                  _log.Info("This will not go to the log");
                  XmlConfigurator.Configure();
                  _log.Info("Ran");
                  

                  这引发了以下问题:

                  1. 我几乎可以肯定我已经在某个版本的 log4net 上看到它在没有添加程序集属性或在 Main 中调用的情况下工作.有人可以向我保证,我不会这么想吗?
                  2. 谁能指出我在文档中明确指出需要配置部分和初始化挂钩的位置 - 希望能说明何时更改,如果更改了?

                  我可以很容易地想象为什么这可能是政策 - 明确初始化步骤以避免意外等,只是我似乎记得并非总是如此......(通常我有配置一个单独的文件,通常会从图片中删除配置部分)

                  I can easily imagine why this might be the policy -- having the initialisation step explicit to avoid surprises etc., it's just that I seem to recall this not always being the case... (And normally I have the config in a separate file, which generally takes configsections out of the picture)

                  推荐答案

                  根据手册中的配置页面:

                  log4net 配置可以使用程序集级属性进行配置,而不是通过编程方式指定.

                  The log4net configuration can be configured using assembly-level attributes rather than specified programmatically.

                  XmlConfiguratorAttribute:log4net.Config.XmlConfiguratorAttribute 允许使用以下属性配置 XmlConfigurator:

                  XmlConfiguratorAttribute: The log4net.Config.XmlConfiguratorAttribute Allows the XmlConfigurator to be configured using the following properties:

                  • 配置文件 ...
                  • ConfigFileExtension ...

                  如果未指定 ConfigFile 或 ConfigFileExtension 属性,则应用程序配置文件(例如 TestApp.exe.config)将用作 log4net 配置文件.

                  If neither of the ConfigFile or ConfigFileExtension properties are specified, the application configuration file (e.g. TestApp.exe.config) will be used as the log4net configuration file.

                  示例用法:

                  // Configure log4net using the .config file
                  [assembly: log4net.Config.XmlConfigurator(Watch=true)]
                  // This will cause log4net to look for a configuration file
                  // called TestApp.exe.config in the application base
                  // directory (i.e. the directory containing TestApp.exe)
                  // The config file will be watched for changes.
                                          
                  

                  我同意这有点模棱两可,但我将示例用法的存在解释为 log4net 不会使用没有上述属性的 .config 文件;并且他们指出您必须使用这两个属性之一,但不要说完全省略该属性的事实,这向我表明该属性(或编程调用)是使用 app.config 所必需的你想要的方式.

                  I agree that it's a bit ambiguous, but I interpret the existence of the example usage to mean that log4net will not use the .config file without the above attribute; and the fact that they point out that you have to use one of the two properties, but do not say anything about leaving out the attribute altogether, suggests to me that the attribute (or programmatic call) is required to use app.config in the way you want.

                  这篇关于log4net 初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)
                  How to store delegates in a List(如何将代表存储在列表中)
                  Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)
                  CreateDelegate with unknown types(具有未知类型的 CreateDelegate)
                  Does Funclt;Tgt;.BeginInvoke use the ThreadPool?(Funclt;Tgt;.BeginInvoke 使用线程池吗?)
                  How to create a delegate to an instance method with a null target?(如何为具有空目标的实例方法创建委托?)

                1. <small id='whtgh'></small><noframes id='whtgh'>

                  <legend id='whtgh'><style id='whtgh'><dir id='whtgh'><q id='whtgh'></q></dir></style></legend>

                        <tbody id='whtgh'></tbody>
                        <tfoot id='whtgh'></tfoot>

                          • <bdo id='whtgh'></bdo><ul id='whtgh'></ul>

                          • <i id='whtgh'><tr id='whtgh'><dt id='whtgh'><q id='whtgh'><span id='whtgh'><b id='whtgh'><form id='whtgh'><ins id='whtgh'></ins><ul id='whtgh'></ul><sub id='whtgh'></sub></form><legend id='whtgh'></legend><bdo id='whtgh'><pre id='whtgh'><center id='whtgh'></center></pre></bdo></b><th id='whtgh'></th></span></q></dt></tr></i><div id='whtgh'><tfoot id='whtgh'></tfoot><dl id='whtgh'><fieldset id='whtgh'></fieldset></dl></div>