tags:

views:

36

answers:

1

Hi,

During startup of my WinForms application I'm noting that there are a couple of points (before the MainForm renders) that do a "MyDataSet.GetInstance()". For the first one the MyLog.Debug line comes through in the VS2008 output window, but for a later one it does work and come through.

What could explain this? What settings could I check at debug time to see why an output line for a MyLog.Debug line doesn't come out in the output window?

namespace IntranetSync
{
    public class MyDataSet
    {
        private static readonly ILog MyLog = LogManager.GetLogger(typeof(MyDataSet));

        public static MyDataSet GetInstance()
        {
            MyLog.Debug("MyDataSet GetInstance() =====================================");
            if (myDataSet == null)
            {
                myDataSet = new MyDataSet();
            }
            return myDataSet;
        }
.
.
.

PS. What I have been doing re log4net repository initialization is putting the following line as a private variables in the classes I use logging - is this OK?

    static class Program
    {
        private static readonly ILog MyLog = LogManager.GetLogger(typeof(MainForm));
.
.
.

    public class Coordinator
    {
        private static readonly ILog MyLog = LogManager.GetLogger(typeof(MainForm));
.
.
.

    public class MyDataSet
    {
        private static readonly ILog MyLog = LogManager.GetLogger(typeof(MyDataSet));
.
.
.
+2  A: 

I'm guessing that the first call to the GetInstance method happens before the log4net repository is initialized. Du you explicitly initialize your repository, and if so: where?

Peter Lillevold
thanks Peter - I've added the answer at the bottom of my question - is there an issue with how I do this?
Greg
Ok, those are initialization of *loggers*, and you're doing that perfectly fine. What I'm asking is how do you configure log4net: are you using XmlConfigurator, BasicConfigurator, the XmlConfigurator attribute or maybe nothing at all? Read up on http://logging.apache.org/log4net/release/manual/configuration.html to see what I'm talking about...
Peter Lillevold
Thanks - forgot about the "BasicConfigurator.Configure();" line I'd put in. It was in the MainForm() however the private instance variable initialisation was doing things before it got to it. I put this line in the Program.cs and it now seems to work fine
Greg