Click here to Skip to main content
15,741,947 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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]
XML
<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.
Posted
Updated 4-Aug-11 9:57am
v4

1 solution

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.
 
Share this answer
 
v2
Comments
pete422 4-Aug-11 13:49pm    
<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">




<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">




<root>
<level value="ALL">
<appender-ref ref="RollingFile">
<appender-ref ref="ConsoleLogger">








This is my config file representing logging. When I debug the code i get perfect logging but its out of random this error keeps popping up.
fjdiewornncalwe 4-Aug-11 14:55pm    
Nothing ever happens "at random" in software. Please review my updated answer.
pete422 4-Aug-11 15:41pm    
Hey thanks for quick reply but I'm afraid i verified for what all u have said. The log is generated all the time Except for certain periods( that's why used the term 'random'). Is there any other basic thing I am missing.
Thanks again for such a quick reply.
pete422 4-Aug-11 15:59pm    
I am sorry for my INCOMPLETE question I have updated the question Hope this will help you understand my problem

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900