通过 Visual Studio 调试 Web 应用程序时,log4net 在哪里写入日志文件?
我正在尝试将 log4net 日志记录添加到我正在编写的 Web 应用程序中。我在 Web 服务方法中得到了这个:
log4net.Config.XmlConfigurator.Configure();
log4net.ILog log = log4net.LogManager.GetLogger(typeof(Methods));
log.Info("Some information");
在 web.config 文件中:
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<authentication mode="Windows" />
<identity impersonate="true"/>
</system.web>
<log4net>
<appender name="LogFileAppender" type="log4net.Appender.RollFileAppender">
<file value="log.txt" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="1MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.SimpleLayout" />
</appender>
<root>
<level value="ALL" />
<appender-ref ref="LogFileAppender" />
</root>
</log4net>
当我通过 Visual Studio 2010 调试它时,我期望日志文件出现在 bin\ 目录中,但那里没有写入任何内容。该方法运行成功,没有任何异常,但我找不到日志文件。关于它应该出现在哪里有什么想法吗?
编辑-一些额外信息: 根据通知区域图标,ASP.Net Development Server 运行在:
C:\Users\jpope\Documents\Visual Studio 2010\Projects\WebApplication1\WebApplication1\
该目录和 \bin\ 子目录的权限均给予 SYSTEM、me 和 Administrators 完全控制权,其他任何人都没有任何访问权限。日志文件不在上面显示的目录或 \bin\ 子目录中。
I'm trying to add log4net logging to a web application I'm writing. I've got this in a web service method:
log4net.Config.XmlConfigurator.Configure();
log4net.ILog log = log4net.LogManager.GetLogger(typeof(Methods));
log.Info("Some information");
And this in the web.config file:
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<authentication mode="Windows" />
<identity impersonate="true"/>
</system.web>
<log4net>
<appender name="LogFileAppender" type="log4net.Appender.RollFileAppender">
<file value="log.txt" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="1MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.SimpleLayout" />
</appender>
<root>
<level value="ALL" />
<appender-ref ref="LogFileAppender" />
</root>
</log4net>
I was expecting the log file to appear in the bin\ directory when I debug it through Visual Studio 2010, but nothing is written there. The method runs successfully without any exceptions, but I can't find the log file. Any ideas as to where it should appear?
Edit - Some extra info:
According to the notification area icon, the ASP.Net Development Server is running in:
C:\Users\jpope\Documents\Visual Studio 2010\Projects\WebApplication1\WebApplication1\
The permissions on this directory and the \bin\ sub-directory both give SYSTEM, me and Administrators full control, and no one else any access. The log file is not in the directory shown above or the \bin\ sub-directory.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您愿意涉足一些低级内容,那么了解一下 可能会很有趣Process Monitor 认为 Web 服务器进程正在尝试写入。至少它比费力地阅读 log4net 文档更有趣。
If you're willing to wade into some low-level stuff, it might be interesting to see what Process Monitor thinks the web server process is trying to write to. At least it would be more fun than wading through the log4net documentation.
也许你应该设置asp.net用户对你的web目录有写权限。
Maybe you should set the asp.net user has the write right for you web directory.
事实证明这是一个配置问题。切换到 FileAppender 而不是 RollFileAppender 效果很好。现在我需要找出
RollFileAppender
配置有什么问题...编辑:它是
RollingFileAppender
,而不是RollFileAppender
。This turned out to be a configuration problem. Switching to a
FileAppender
instead of a RollFileAppender works fine. Now I need to find out what's wrong with theRollFileAppender
configuration...Edit: It's a
RollingFileAppender
, not aRollFileAppender
.