在IIS7上部署时,log4net不会创建日志文件 [英] log4net doesn't create log file when deployed on IIS7
问题描述
大家早上好,
我有一个log4net问题,当我在我的
本地机器上进行开发时,该问题并不存在,但是一旦我部署了应用程序到服务器,log4net停止工作。
I have a log4net issue that didn't exist when I was developing on my local machine, but once I deployed the application to a server, log4net stopped working.
这是服务器配置:
-Windows XP SP3
-IIS 7
- framework .Net v4
This is the server configuration : -Windows XP SP3 -IIS 7 -framework .Net v4
这是网站web.config中的log4net配置:
This is the log4net configuration in the web.config of the website:
<configuration>
<log4net>
<root>
<level value="DEBUG" />
<appender-ref ref="LogFileAppender" />
</root>
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="log.txt" />
<param name="AppendToFile" value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="30MB" />
<staticLogFileName value="false" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%-5p%d{yyyy-MM-dd hh:mm:ss} – %m%n" />
</layout>
</appender>
</log4net>
</configuration>
我还有一个类库,这是它的App.config文件:
I also have a class library and this is its App.config file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net"/>
</configSections>
<log4net>
<root>
<level value="DEBUG" />
<appender-ref ref="LogFileAppender" />
</root>
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender" >
<param name="File" value="log.txt" />
<param name="AppendToFile" value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="30MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%-5p%d{yyyy-MM-dd hh:mm:ss} – %m%n" />
</layout>
</appender>
</log4net>
</configuration>
这是我在每个班级调用日志功能的方式:
This is how I call the log function on every class:
private static readonly ILog log = LogManager.GetLogger(typeof(AppDomain));
...这就是我所说的:
...and this is how i call it :
log.Error("\n\t=>" + ex.GetBaseException().Message + "\n\r" + " @ " + Environment.StackTrace);
推荐答案
可能是你没有权限写到文件'log.txt'。
It could be that you do not have permissions to write to the file 'log.txt'.
我不知道当前目录是什么,但它不太可能是IIS可以写入的地方。
I don't know what the current directory would be but it's unlikely to be somewhere IIS can write to.
您需要在某处创建一个文件夹并授予IIS写入权限,我知道您需要授予对IIS_IUSRS组的访问权限,然后指定该文件的绝对路径。例如。
You need to create a folder somewhere and grant access for IIS to write to it, I understand you need to grant access to the IIS_IUSRS group and then specify the absolute path to that file. e.g.
<param name="File" value="D:\Logs\log.txt" />
..使用您首选位置的路径。
..using the path to your preferred location.
这篇关于在IIS7上部署时,log4net不会创建日志文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!