包含log4net后的WebPart错误

时间:2012-03-29 12:27:55

标签: c# sharepoint-2007 log4net-configuration

在WebPart Code中包含log4net后,我开始收到WebPart错误。这是Web.Config Entry。

任何人都可以确定我缺少的东西

<configuration>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
  </configSections>
  <log4net>
      <appender name="LogFileAppender" type="log4net.Appender.FileAppender">
        <param name="File" value="C:\\Logs\\Log4Net.txt" />
        <param name="AppendToFile" value="true" />
        <layout type="log4net.Layout.PatternLayout">
           <param name="Header" value="[Started...]&#xD;&#xA;" />
           <param name="Footer" value="[...Stopped]&#xD;&#xA;" />
           <param name="ConversionPattern" value="%date [%thread] %-5level %logger - %ndc - %message%newline" />
        </layout>
      </appender>
      <root>
         <level value="INFO" />
         <appender-ref ref="LogFileAppender" />
      </root>
 </log4net>

Webpart中的代码如下:

public class Test
{
    private static readonly ILog logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
    //Constructor
    Test()
    {
         XmlConfigurator.Configure();
    }
    protected override void CreateChildControls()
    {
          try
          {
                //Code
          }
          catch(Exception ex)
          {
               logger.Error(ex.Message.toString());
          }
     }
 }

0 个答案:

没有答案