Click here to Skip to main content
15,882,889 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have this code:

Using Libs;

public static readonly log4net.ILog log =

 static void Main(string[] args)


Now Libs NameSpace contains:

namespace Libs
    class Libs
        public void Connect(string Uri)
            log.Info("Connecting to Server : " + Uri);

Within Libs .. "log" is not recognised. What do i need to change to fix this? If i use log.Info in Main it just works fine

What I have tried:

i tried to change public void etc.
Updated 17-Apr-17 9:58am
Amien90 17-Apr-17 15:53pm    
This works:

IQ.Program.log.Info("Connecting to Server : " + Uri);

It is already needed? or is it possible to make it shorter so that "log.Info" works?
[no name] 17-Apr-17 15:54pm    
You would need to move the declaration for log into the Libs class.

1 solution

You can put your Log instance in Program, making it globally available throughout the app.

This is somewhat lazy but I think justified for a logger which is truly a single resource and hardly worth the effort of packaging in a more fancy way (a singleton being good alternative).
Share this answer

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