Re: log4net mysteriously stops logging



RobinS wrote:
Comments inline...

"Jeroen Mostert" <jmostert@xxxxxxxxx> wrote in message news:47e40559$0$14350$e4fe514c@xxxxxxxxxxxxxxxxx
log4net questions are really not appropriate for any language-specific group. Followup-to .general, which is at least mildly more suitable.

That's just your opinion.

Yes, to which I'm entitled, etcetera and so forth. What can I say? I'm a stickler for useless traditions that are widely ignored.

Lots of people post stuff that is only barely related to C# or VB in
those groups.

Lots of people are ignorant and boorish; I see no reason to join the herd.

However, since I'm desperate (which I think I've mentioned), I'm going to
humor you.

Good, because I'm not posting in the other groups. You're free to disperse your replies across Usenet however you want...

ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); Does that matter?

Is this in every method that logs, just the c'tor, or some general class? This is an incredibly roundabout way of getting a logger, since the usual approach is

class A {
private static ILog log = LogManager.GetLogger(typeof(A));
...

Which creates one logger for every class when it's first referenced and uses no expensive reflection.


We're using that in every place we do logging. I know about the performance hit of Reflection, but really our app has about 10 forms&dialogs, a bunch of user controls (20-30?), and maybe 15 classes. It's not huge huge. Since the guy who put the logging in did this, the rest of us just carried it through. Doesn't your statement do the same as mine, but w/o the reflection?

Yes, but in addition, my call only retrieves a logger *once*. Retrieving it in each and every method is pretty pointless (and a lot of typing, redundancy, and redundancy). If the performance hit doesn't matter in your case, that's good, but it's not something you want to make a habit of.

We have a separate .config file just for log4net. It gets deployed with the project. The first time the user runs it, it opens it and saves it under a folder under their MyDocuments, and reads it from there. We call XmlConfigurator.Configure and pass it the FileInfo object that represents the config file.

This sounds important. Can you repro the code, in particular the .Configure call?

Okay, more info. I had our QA person run the application repeatedly. Sometimes the logging stops right away, sometimes it stops after she's run through the app a couple of times. It's not 100% reproducible. With the debugging in log4net enabled, I found the following:


log4net: Hierarchy: Shutdown called on Hierarchy [log4net-default-repository]
log4net: XmlConfigurator: configuring repository [log4net-default-repository] using file [C:\Users\Jeanne\Documents\GoldMail\GoldMailLog.txt]
log4net: XmlConfigurator: configuring repository [log4net-default-repository] using stream
log4net:ERROR XmlConfigurator: Error while loading XML configuration
System.Xml.XmlException: Data at the root level is invalid. Line 1, position 1.

And behold the problem. It's shutting down the repository and reinitializing it, but that simply fails. This comes from the repository reconfiguring itself.

Let's see. Can you repro the lines right above the "Shutdown called"? Are you using ConfigureAndWatch() to initialize logging or is any of the assemblies using a log4net attribute in its AssemblyInfo.cs that does?

Is anything writing to the log4net config file while the application is running? Something you don't expect? An external application? If you mark the file readonly or deny write permissions, does the error still happen?

That seems really bad. My guess is that this is where it's shutting down the logging. Note that the configuration file is loaded just fine at the beginning of the application. Why would it be trying to load it again, and why would it fail?

It could load it again if it was told to do so whenever the file changed. It could also do this if the logging system was explicitly asked to reconfigure itself. The lines just above "Shutdown called" should provide more insight into what's the case.

--
J.
.



Relevant Pages

  • Re: log4net mysteriously stops logging
    ... I posted it to both because I'm desperate, I've seen log4net q's here, and the people here are exceptionally smart. ... You have to close the app and restart it and the logging will restart. ... I turned on internal logging in the config manager, and redirected the output to a file. ... log4net: DefaultRepositorySelector: Creating repository for assembly ...
    (microsoft.public.dotnet.general)
  • Re: log4net mysteriously stops logging
    ... We call XmlConfigurator.Configure and pass it the FileInfo object that represents the config file. ... Sometimes the logging stops right away, sometimes it stops after she's run through the app a couple of times. ... With the debugging in log4net enabled, ... you might try running your application with Managed Debugging Assistants enabled. ...
    (microsoft.public.dotnet.general)
  • Re: How to package a logging.config file?
    ... should avoid configuring logging using a config file - this is because ... As long as I don't tweak the root logger, is it safe to use a config ...
    (comp.lang.python)
  • Re: How do I open a console from a Winform App?
    ... It can log debug messages to almost anything, ... change the config file for the level of logging you want while your ... This also works as a source for Log4Net. ... problem with this is that debug logging only occurs for debug builds. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: [BUG] linux-next: Tree for May 19/20/21 - BUG at arch/x86/kernel/io_apic_64.c:353!
    ... Can you include the config when you send these, ... from next report will send across the .config file also. ... for the kernel bug discussed. ... # PCI IDE chipsets support ...
    (Linux-Kernel)