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

C#
Using Libs;

public static readonly log4net.ILog log =
 log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

 static void Main(string[] args)

{
Libs.Connect("www.gmail.com");
}


Now Libs NameSpace contains:

C#
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.
Posted
Updated 17-Apr-17 9:58am
Comments
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