log4net在发布到服务器时无法创建日志文件
我正在使用 log4net 来记录我的 asp.net 应用程序。但是,当我在本地主机上运行时,日志文件运行良好。但是当我发布到 IIS 时,log4net 无法创建日志文件。我可以知道是什么问题吗?我错过了什么配置吗?
这是我的 log4net.config。
<log4net debug="true">
<appender name="LogFileAppender" type="log4net.Appender.FileAppender">
<param name="File" value="D:\\LewreLogFile1.log"/>
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%-5p %d %5rms %-22.22c{1} %-18.18M - %m%n" />
</layout>
</appender>
<logger name="File">
<level value="All" />
</logger>
<root>
<level value="All" />
<appender-ref ref="LogFileAppender" />
</root>
和我的 global.asax
void Application_Start(object sender, EventArgs e)
{
string l4net = Server.MapPath("~/log4Net.config");
log4net.Config.XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo(l4net));
}
I am using log4net for logging my asp.net application. However the log file is working well when I run on my localhost. But when I publish to IIS, the log4net is not able to create a log file. May I know what is the problem? Did I miss any configuration?
Here is my log4net.config.
<log4net debug="true">
<appender name="LogFileAppender" type="log4net.Appender.FileAppender">
<param name="File" value="D:\\LewreLogFile1.log"/>
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%-5p %d %5rms %-22.22c{1} %-18.18M - %m%n" />
</layout>
</appender>
<logger name="File">
<level value="All" />
</logger>
<root>
<level value="All" />
<appender-ref ref="LogFileAppender" />
</root>
and my global.asax
void Application_Start(object sender, EventArgs e)
{
string l4net = Server.MapPath("~/log4Net.config");
log4net.Config.XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo(l4net));
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须授予 IIS 执行 IO 的权限。更改您的应用程序池身份或向其尝试访问的文件系统授予 IUSR 权限。
You have to give IIS permission to do IO. Change your App pool identity or give IUSR permission the the file system it's trying to access.