2012-01-19 65 views
1

我花了整個上午都通過了一整套的可能性,爲什麼log4net的不寫文件時,根據設置的SharePoint 2010log4net的,缺少魔法

我已經試過單獨的log4net的文件涉水路由,但我目前正在嘗試它在web.config中配置它。

我在web.config中更新了對介質的信任,而log4net dll也在GAC中。當我斷點時,我的記錄器看起來不錯,所有日誌記錄啓用,但是.Info()通過沒有錯誤,但日誌文件沒有創建。

祝你好運我已經給所有人& asp.net應用程序池runas用戶完全控制根日誌文件夾。這裏的配置片斷和App_Start代碼:

<configuration> 
    <configSections> 
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821" /> 
    ... 

    <log4net> 
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender"> 
    <file value="c:\temp\log.txt" /> 
    <appendToFile value="true" /> 
    <rollingStyle value="Size" /> 
    <maxSizeRollBackups value="10" /> 
    <maximumFileSize value="5MB" /> 
    <staticLogFileName value="true" /> 
    <layout type="log4net.Layout.PatternLayout"> 
    <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" /> 
    </layout> 
</appender> 
    </log4net> 




    private static ILog logger; 

    protected void Application_Start(object sender, EventArgs e) 
    { 
     ////This tells log4net where to go and look for its configuration file and also to watch it for any changes 
     //log4net.Config.XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo(@"C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\Config\Moogle\Log4Net.config")); 

     SPSecurity.RunWithElevatedPrivileges(delegate 
     { 
      log4net.Config.XmlConfigurator.Configure(); 

      logger = LogManager.GetLogger("Moogle.Web"); 
      logger.Info("Application_Start Fired"); 
     }); 
    } 

編輯 已經更新我的配置上面(見我的答案),我仍然得到log4net的消息:

log4net: XmlHierarchyConfigurator: Hierarchy Threshold [] 
log4net: Logger: No appenders could be found for logger [Moogle.Web] repository [log4net-default-repository] 
log4net: Logger: Please initialize the log4net system properly. 

任何想法?

回答

1

已經做了一些挖掘,我發現log4net的非常有用的特性要求它做自己的診斷。

您添加follwing應用程序設置:

<add key="log4net.Internal.Debug" value="true"/> 

及以下部分:

<configuration> 
    ... 

    <system.diagnostics> 
     <trace autoflush="true"> 
      <listeners> 
       <add 
        name="textWriterTraceListener" 
        type="System.Diagnostics.TextWriterTraceListener" 
        initializeData="C:\tmp\log4net.txt" /> 
      </listeners> 
     </trace> 
    </system.diagnostics> 

    ... 
</configuration> 

我現在能看到它的明顯的配置,這是錯誤的,因爲它是報告:

log4net: XmlConfigurator: configuring repository [log4net-default-repository] using .config file section 
log4net: XmlConfigurator: Application config file is [C:\inetpub\wwwroot\wss\VirtualDirectories\MOOGLEDEV0180\web.config] 
log4net: XmlConfigurator: Configuring Repository [log4net-default-repository] 
log4net: XmlHierarchyConfigurator: Configuration update mode [Merge]. 
log4net: XmlHierarchyConfigurator: Logger [root] Level string is [ALL]. 
log4net: XmlHierarchyConfigurator: Logger [root] level set to [name="ALL",value=-2147483648]. 
log4net: XmlHierarchyConfigurator: Hierarchy Threshold [] 
log4net: Logger: No appenders could be found for logger [Moogle.Web] repository [log4net-default-repository] 
log4net: Logger: Please initialize the log4net system properly. 

而我一直在想這是權限......那麼這個配置怎麼了?

編輯 - 工作配置

這裏有一個獨立的log4net.config,做工作

<?xml version="1.0"?> 
<configuration> 
    <configSections> 
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821"/> 
    </configSections> 
    <log4net> 
    <appender name="RollToFile" type="log4net.Appender.RollingFileAppender"> 
     <file value="C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\Logs\Moogle\Moogle.Web.Log" /> 
     <appendToFile value="true" /> 
     <rollingStyle value="Size" /> 
     <maxSizeRollBackups value="10" /> 
     <maximumFileSize value="5MB" /> 
     <staticLogFileName value="true" /> 
     <layout type="log4net.Layout.PatternLayout"> 
     <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" /> 
     </layout> 
    </appender> 
    <root> 
     <!-- Value of priority may be ALL, DEBUG, INFO, WARN, ERROR, FATAL, OFF --> 
     <priority value="ALL"/> 
     <appender-ref ref="RollToFile"/> 
    </root> 
    </log4net> 
</configuration> 
(您剪切和粘貼從謹慎!)