在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...]
" />
<param name="Footer" value="[...Stopped]
" />
<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());
}
}
}