Log4net无法写入,仅创建空文件,但不写入实际日志
我无法使用 log4net 写入日志任何信息、错误、调试,我尝试了向网络服务授予权限的所有内容,每个人都访问目录 asp.net 临时文件夹、日志文件夹,甚至 c:\,
它只是创建一个空文件。但不写日志
可能是什么问题
,谢谢 拉吉
i am unable to write log any info, error, debug using log4net, i tried everything gave permsission to network service, everyone to directories asp.net temp folder, log folder, even c:\,
it just create a empty file. but do not write log
what could be the issue
Thx
Raj
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我的猜测是,在您的配置文件中,您没有指定布局模式。通常,您的附加程序中会有如下所示的内容:
指定要写入日志的内容。如果你没有这个,我怀疑它会写任何东西。
我同意评论中的观点,他们说这可能不是权限问题,因为文件是创建的。要测试这是否正确,您可以将附加程序添加到输出到控制台的配置中。然后您可以在调试应用程序时观察输出。如果这也不起作用,您就知道问题不是权限问题。
我能给出的最好建议是将您的配置文件与工作文件进行比较。确保每个部分在工作配置中都有一个对应部分,或者您知道为什么不需要有一个对应部分。这是我在 log4net 上写的一篇文章,其中包括对配置每个部分的解释,并展示了如何编写它们:
http://www.codeproject.com/KB/dotnet/Log4net_Tutorial.aspx
如果所有这些都没有帮助,请在您的问题中发布您的配置文件文本,以便我们可以查看它。
My guess would be that in your config file, you didn't specify a layout pattern. Normally, you have something that looks like this inside your appender:
That specifies what to write to the log. If you don't have that, I doubt it will write anything.
I agree with those in the comments who said this probably isn't a permissions issue because the file gets created. To test that this is true, you could add an appender to your config that outputs to the console. Then you could watch the output as you debug your application. If that doesn't work either, you know the issue isn't a permissions issue.
The best suggestion I can give would be to compare your config file with a working one. Make sure that every section has a counterpart in the working config or that you know why it doesn't need to have one. Here is an article I wrote on log4net that includes explanations on every section of the config and it shows how to write them:
http://www.codeproject.com/KB/dotnet/Log4net_Tutorial.aspx
If all of this doesn't help, please post your config file text in your question so we can look through it.
导致此问题的一个可能原因可能是日志记录级别。
检查日志记录级别是否设置为 FATAL,如果是这种情况,请尝试将 web.config: 的这一部分替换
为: 此外
,不要忘记检查 web.config 部分中某些
小节的最终发生情况。在这种情况下,即使日志记录级别设置为 DEBUG(例如)并且您
输入您的代码,例如:
它总是返回空白,但如果您编写例如:
因此尝试注释掉过滤器部分以及这一行
,最后您应该让它工作!
希望这有帮助
One possible cause of this issue could be the Logging Level.
Check if Logging level is set to FATAL and if that is the case try replacing this part of the web.config:
with this:
Furthemore don't forget to check in web.config section the eventual occurences of some
subsection. In this case even though the logging level is set to DEBUG (for example) and you
put in your code somethig like:
it will always return blank but if you write for example:
Try therefore to comment out the filter sections and also this line
a this point finally you should get it working!!
Hope this helps
如果您使用自己的 PatternLayout,请在配置文件中查看以前的模式类命名空间:
If you use own PatternLayout, see in config file yore pattern class namespace: