记录问题 [英] Problem with Logging

查看:81
本文介绍了记录问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我已经编写了一项服务,并已在我的代码中建立了日志记录(使用log4net).我遇到了一个问题(错误),当此错误出现时,我的日志文件未生成,是否有任何建议和针对我所犯的错误.
问候
皮特

[回答问题]

Hi,
I have written a service and have established logging throughout my code (using log4net). I am having an issue (bug) and when this bug arises my log files donot get generated, are there any suggestions and adivces to as what mistake I have done.
Regards
Pete

[Answer moved to question]

<log4net>
      <appender name="ConsoleLogger" type="log4net.Appender.ConsoleAppender">
         <!-- A1 uses PatternLayout -->
         <layout type="log4net.Layout.PatternLayout">
            <conversionpattern value="%-4timestamp [%thread] %-5level %logger %ndc - %message%newline" />
         </layout>
      </appender>
 
      <appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
         <file value="C:\Logs\NotificationServices\Events.log" />
         <appendtofile value="true" />
         <maximumfilesize value="5000KB" />
         <maxsizerollbackups value="2" />
         <layout type="log4net.Layout.PatternLayout">
            <conversionpattern value="%date %level %thread %logger - %message%newline" />
         </layout>
      </appender>
 
      <root>
         <level value="ALL" />
         <appender-ref ref="RollingFile" />
         <appender-ref ref="ConsoleLogger" />
      </root>
 
   </log4net>



这是我的配置文件.我已经能够完美地生成日志记录了
但是问题是随机记录失败,从某种意义上来说,失败是因为只有第二个我的服务处于活动状态,才生成一个日志语句.这就是我的问题.



This is my configuration file. I have been able to generate the logging perfectly
but the problem is that out of random the logging fails, FAILS IN THE SENSE THERE IS ONLY ONE LOG STATEMENT GENERATED EVERY SECOND MY SERIVE IS ACTIVE. So that is my issue.

推荐答案

调试代码.使用单元测试来阻塞测试日志编写器的创建,并确认日志编写代码是有效的.没有看到您建议的所有日志记录配置.

[更新]
您可能需要重新访问应用程序中尝试写入日志的所有实例.在一种或多种情况下,您可能没有向记录器提供适当的参数.确保始终通过发送的值进行初始化.您可以通过逐步执行过程来找出发生这种情况的位置,以从用户的角度找出导致错误的原因.通常应该在使用单元测试之类的情况下发生这种情况,但是,如果这种情况不可用,则没有理由您也不能手动进行.
Debug your code. Use unit tests to block test the log writer creation and confirm that the log writing code is valid. Without seeing your configuration for the logging that is about all I could suggest.

[Update]
You may need to revisit all the instances in your application where you attempt to write to the log. It may be that in one or more of those instances you are not providing appropriate arguments to the logger. Make sure that the values you are sending through are always initialized. You may be able to narrow down where this is occurring by stepping through your processes to find out what action from a user''s perspective is causing the error. This should usually happen with the use of unit testing and such, but if that isn''t available, there is no reason why you can''t do it manually as well.


这篇关于记录问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆