Web.Config 中的 Log4Net 部分生成错误
所以我尝试在我的 Web .NET 4.0 应用程序中设置 Log4Net。我已将正确的 .dll 添加到我的项目中,并将以下内容附加到我的 Web.Config 文件中作为启动项:
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
<root>
<level value="DEBUG" />
<appender-ref ref="RollingLogFileAppender" />
</root>
</configSections>
<log4net debug="true">
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="C:\\TestProj\\TestLog.txt" />
<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>
但是,如果我将“log4net”部分附加到 Web.Config,我将收到错误消息
无法在 Web 服务器上启动调试。常见的请参见帮助 配置问题......
确保服务器运行正常。验证没有语法 web.config 中的错误......
注意 我可以删除本节的所有内部结构,只留下声明:
<log4net></log4net>
并且我仍然会得到相同的错误。
有人可以给我一些关于如何追踪这个错误的指示吗?
So I am trying to set up Log4Net in my Web .NET 4.0 application. I have added the correct .dll to my project and have appended the following to my Web.Config file as starters:
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
<root>
<level value="DEBUG" />
<appender-ref ref="RollingLogFileAppender" />
</root>
</configSections>
<log4net debug="true">
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="C:\\TestProj\\TestLog.txt" />
<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>
However, if I append the "log4net" section to Web.Config, I will receive the error message
Unable to start debugging on the web server. See help for common
configuration problems.....Make sure the server is running correctly. Verify there are no syntax
errors in the web.config........
NOTE
I can remove all the internals of this section and leave only the declaration:
<log4net></log4net>
and I will still get the same error.
Can someone give me some pointers on how to track down this error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于不确定如何开始的开发人员,以下可能会有所帮助
app.config 中的 ConfigSections
请记住告诉您的应用程序,如果您打算使用某个库正在引入自定义配置部分,我我不太确定它是否是强制性的,但我总是将其用作根
标记中的第一部分。app.config 中的 log4net 配置
log4net 中提供了多种不同的附加程序,但我通常使用 RollingFileAppender,因此我在本示例中使用相同的附加程序,您可以找到其余的 此处。
更新 AssemblyInfo.cs 文件
每当我必须创建新项目时,我总是会错过这一步。因此,请记住,您必须告诉您的应用程序监视
XMLConfigurator
来执行 log4net 的配置,因此 AssemblyInfo.cs 文件末尾包含以下行:开始使用
请记住包含log4net.dll 的引用然后使用以下代码行在类中初始化记录器
最后让我们使用它就像下面的
快乐伐木:)
For developers who are not sure exactly how to get started following might be a help
ConfigSections in app.config
Remember to tell your application that a library is introducing a custom configuration section are you are intended to utilize, I am not perfectly sure if it is mandatory or not but I always use it as first section within root
<configuration>
tag.log4net config in app.config
There are quite a variety of different appenders available in log4net but I usually use RollingFileAppender so I am using the same one in this sample, you can find rest of those here.
Update AssemblyInfo.cs file
I always miss this step whenever I have to create a new project. So remember you have to tell your application to watch for
XMLConfigurator
to perform configuration of log4net, so following line goes at the end of AssemblyInfo.cs file:Get Started
Remember to include the reference of log4net.dll then use following line of code to initialize logger within a class
And at the end lets use it like following
Happy Logging :)
在 log4net 文档 主页查看示例配置。
您很可能丢失了所需的标签。
Take a look at a sample configurations at log4net documentation homepage.
Chances are you've misplaced required tags.