Log4net无法写入,仅创建空文件,但不写入实际日志

发布于 2024-11-16 10:41:31 字数 147 浏览 3 评论 0原文

我无法使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

诠释孤独 2024-11-23 10:41:32

我的猜测是,在您的配置文件中,您没有指定布局模式。通常,您的附加程序中会有如下所示的内容:

<layout type="log4net.Layout.PatternLayout">
  <conversionPattern value="%date [%thread] %level %logger - %message%newline" />
</layout>

指定要写入日志的内容。如果你没有这个,我怀疑它会写任何东西。

我同意评论中的观点,他们说这可能不是权限问题,因为文件是创建的。要测试这是否正确,您可以将附加程序添加到输出到控制台的配置中。然后您可以在调试应用程序时观察输出。如果这也不起作用,您就知道问题不是权限问题。

我能给出的最好建议是将您的配置文件与工作文件进行比较。确保每个部分在工作配置中都有一个对应部分,或者您知道为什么不需要有一个对应部分。这是我在 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:

<layout type="log4net.Layout.PatternLayout">
  <conversionPattern value="%date [%thread] %level %logger - %message%newline" />
</layout>

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.

左秋 2024-11-23 10:41:32

导致此问题的一个可能原因可能是日志记录级别
检查日志记录级别是否设置为 FATAL,如果是这种情况,请尝试将 web.config: 的这一部分替换

 <log4net>
         .....
         <root>
              <level value="FATAL" /> 
              <appender-ref ref="RollingFileAppender" />
            </root>
         .....
    </log4net>

为: 此外

<log4net>
    ......
    <root>
         <level value="DEBUG" /> 
           <appender-ref ref="RollingFileAppender" />
       </root>
    ....
</log4net>

,不要忘记检查 web.config 部分中某些

 <filter type="log4net.Filter.StringMatchFilter">
    <stringToMatch value="test" />
  </filter>

小节的最终发生情况。在这种情况下,即使日志记录级别设置为 DEBUG(例如)并且您
输入您的代码,例如:

log.Debug("Db quering...");

它总是返回空白,但如果您编写例如:

log.Debug("test: Db quering...");

因此尝试注释掉过滤器部分以及这一行

  <filter type="log4net.Filter.DenyAllFilter" />

,最后您应该让它工作!

希望这有帮助

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:

 <log4net>
         .....
         <root>
              <level value="FATAL" /> 
              <appender-ref ref="RollingFileAppender" />
            </root>
         .....
    </log4net>

with this:

<log4net>
    ......
    <root>
         <level value="DEBUG" /> 
           <appender-ref ref="RollingFileAppender" />
       </root>
    ....
</log4net>

Furthemore don't forget to check in web.config section the eventual occurences of some

 <filter type="log4net.Filter.StringMatchFilter">
    <stringToMatch value="test" />
  </filter>

subsection. In this case even though the logging level is set to DEBUG (for example) and you
put in your code somethig like:

log.Debug("Db quering...");

it will always return blank but if you write for example:

log.Debug("test: Db quering...");

Try therefore to comment out the filter sections and also this line

  <filter type="log4net.Filter.DenyAllFilter" />

a this point finally you should get it working!!

Hope this helps

四叶草在未来唯美盛开 2024-11-23 10:41:32

如果您使用自己的 PatternLayout,请在配置文件中查看以前的模式类命名空间:

<layout type="My.PatternClass.Namespace.MyPatternLayout">
    ...
</layout>

If you use own PatternLayout, see in config file yore pattern class namespace:

<layout type="My.PatternClass.Namespace.MyPatternLayout">
    ...
</layout>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文