Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I always consider logging from the start. </p> <p>Firstly there is the decision of which logging framework to use, but that is generally a quick choice. I personally often use log4net, which means each class uses the static LogManager.GetLogger to get an instance of a logger. The actual behaviours of each log call is then defined in config (where should I log too, what level should I log at, etc).</p> <p>However, more importantly, you should be thinking of <em>what needs logging</em> as you are actually developing your application. There is no point at which you are more tuned into your code than when you are writing it, and you probably have a better idea of what needs logging then than at any other time. It is far easier to retrospectively remove overly verbose logging that you don't need that add logging that should be there.</p> <p>So yes - always think about logging as you start your application, don't try and retro-fit it if you can help it.</p> <p><strong>[EDIT: In response to your question about how to inject]</strong></p> <p>Possibly the simplest approach (assuming you are not using an IoC container) is to go down the route of property or constructor injection. Personally, I much prefer the latter for this sort of thing, so I would end up with something like this for log4net:</p> <pre><code>public class MyClass { private readonly ILog _logger; // usually I don't supply a logger directly, // hence I let this ctor get a logger from the log manager. public MyClass() : this (LogManager.GetLogger(typeof(MyClass))) { } // this ctor only gets called directly if I want to mock out logging public MyClass(ILog logger) { _logger = logger; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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