Note that there are some explanatory texts on larger screens.

plurals
  1. POInitialize log4Net as early as possible with NUnit
    text
    copied!<p>I'm wondering what is the best way to initialize log4Net in a NUnit project. Of course I want to call the init code (ie. <code>XmlConfigurator.Configure()</code>) as soon as I can to get as many early log output as I can. But since my project is run through NUnit, I have little control on its entry point.</p> <p>According to NUnit documentation, it should call some constructors first, then a method marked with the <code>[SetUp]</code> attribute in a class marked with <code>[TestFixtureSetup]</code>.</p> <p>So, First, I created a static helper class which I can call several times without trouble. </p> <pre><code> public static class LoggingFacility { private static bool _loggerIsUp = false; public static void InitLogger() { if (_loggerIsUp == false) XmlConfigurator.ConfigureAndWatch(f); _loggerIsUp = true; } } </code></pre> <p>Then, I made all my <code>[TestFixtureSetup]</code> inherit a single one that does pretty much nothing else than calling <code>LoggingFacility.initLogger()</code>. But that still leaves all constructors that are run earlier, in an order I can only assume random. And moreover, it will probably do some static initializations before I am even able to execute some code.</p> <p>In fact, as I can see in my log, the first 4 seconds or so of execution are completely unrecorded.</p> <p>Does it mean I will have to call my <code>InitLogger()</code> in every constructor and forbid the use of any static initializer? That's tough job!</p> <p>Does somebody know a magic trick with this?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload