我无法让 log4net 在 ASP.Net 网络表单中记录任何内容。这就是我正在做的事情:
网页配置
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net"/>
</configSections>
<log4net>
<appender name="MyLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="C:\inetpub\MySite\Logs\MyLog.log"/>
<param name="AppendToFile" value="true"/>
<rollingStyle value="Size"/>
<maxSizeRollBackups value="10"/>
<maximumFileSize value="10KB"/>
<staticLogFileName value="true"/>
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%-5p%d{yyyy-MM-dd hh:mm:ss} – %m%n"/>
</layout>
</appender>
<logger name="MyLogger">
<level value="ALL"/>
<appender-ref ref="MyLogFileAppender"/>
</logger>
</log4net>
...
全球.asax
<%@ Application Language="VB" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="log4net" %>
<script runat="server">
Public Shared Logger As ILog
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
Config.XmlConfigurator.ConfigureAndWatch(New FileInfo("Web.config"))
End Sub
测试.aspx
Protected Sub cmdTest_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdTest.Click
Dim logger As log4net.ILog = log4net.LogManager.GetLogger("MyLogger")
logger.Debug("A test debug message")
End Sub
我已授予“所有人”对“C:\inetpub\MySite\Logs”文件夹的访问权限,但仍然没有出现日志。任何想法我可能做错了什么?