You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by Erlis Vidal <Ev...@affiliated.ca> on 2007/10/23 23:10:53 UTC

Config log4net in n-tiear application Framework 2.0!

Hi everyone!

 

I want to configure log4net in order to use the same configuration file
(with the watch option active) in my n-tier application!

 

I have the following structure in my solution:

 

Website (as a web application project)

Business (as a class library project)

Data (as a class library project)

Test (as a class library project)

 

I want to be able to log messages in any of those layers using the same
log4net configuration file... 

Can you provide any suggestion for the right configuration? 

 

Regards,

Erlis


RE: Config log4net in n-tiear application Framework 2.0!

Posted by "Walden H. Leverich" <Wa...@TechSoftInc.com>.
> For each project, reference the log4net dll and put the following line
in the assemblyInfo file:

 

I agree with referencing the log4net.dll, but I don't think you need to
put the [assembly...] attribute in. At least not if the top-level
application (asp.net) does the configure through code. We don't use the
attribute at all and we get logging from all our levels. Our ASP.Net
code does though do this in global.sasx:

 

        protected void Application_Start(object sender, EventArgs e)

        {

            string configFile =
Server.MapPath(ConfigurationManager.AppSettings["log4net-config-file"]);

            log4net.Config.XmlConfigurator.ConfigureAndWatch(new
System.IO.FileInfo(configFile));

 

            log = log4net.LogManager.GetLogger(

 
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

 

            log.InfoFormat("Watching '{0}'", configFile);

        }

 

-Walden

 

-- 

Walden H Leverich III
Tech Software
(516) 627-3800 x3051

WaldenL@TechSoftInc.com
http://www.TechSoftInc.com
<BLOCKED::blocked::http://www.techsoftinc.com/> 

Quiquid latine dictum sit altum viditur.
(Whatever is said in Latin seems profound.)

From: Dave McEwan [mailto:dmcewan@harmonyis.com] 
Sent: Tuesday, October 23, 2007 5:18 PM
To: Log4NET User
Subject: RE: Config log4net in n-tiear application Framework 2.0!

 

 

For each project, reference the log4net dll and put the following line
in the assemblyInfo file:

 

            [assembly: log4net.Config.XmlConfigurator(
ConfigFile="log4net.config",Watch=true )]

 

Now at the class level for each class add the following line to create
an instance of the logger:

 

            private static readonly ILog log = LogManager.GetLogger(
MethodBase.GetCurrentMethod().DeclaringType);

 

 

 

Now you can make calls like so from your methods:

 

            log.Error(ex.Message.ToString(), ex);

 

 

Hope that helps

Dave

 

________________________________

From: Erlis Vidal [mailto:Evidal@affiliated.ca] 
Sent: Tuesday, October 23, 2007 5:11 PM
To: log4net-user@logging.apache.org
Subject: Config log4net in n-tiear application Framework 2.0!

 

Hi everyone!

 

I want to configure log4net in order to use the same configuration file
(with the watch option active) in my n-tier application!

 

I have the following structure in my solution:

 

Website (as a web application project)

Business (as a class library project)

Data (as a class library project)

Test (as a class library project)

 

I want to be able to log messages in any of those layers using the same
log4net configuration file... 

Can you provide any suggestion for the right configuration? 

 

Regards,

Erlis


RE: Config log4net in n-tiear application Framework 2.0!

Posted by Dave McEwan <dm...@harmonyis.com>.
 

For each project, reference the log4net dll and put the following line
in the assemblyInfo file:

 

            [assembly: log4net.Config.XmlConfigurator(
ConfigFile="log4net.config",Watch=true )]

 

Now at the class level for each class add the following line to create
an instance of the logger:

 

            private static readonly ILog log = LogManager.GetLogger(
MethodBase.GetCurrentMethod().DeclaringType);

 

 

 

Now you can make calls like so from your methods:

 

            log.Error(ex.Message.ToString(), ex);

 

 

Hope that helps

Dave

 

________________________________

From: Erlis Vidal [mailto:Evidal@affiliated.ca] 
Sent: Tuesday, October 23, 2007 5:11 PM
To: log4net-user@logging.apache.org
Subject: Config log4net in n-tiear application Framework 2.0!

 

Hi everyone!

 

I want to configure log4net in order to use the same configuration file
(with the watch option active) in my n-tier application!

 

I have the following structure in my solution:

 

Website (as a web application project)

Business (as a class library project)

Data (as a class library project)

Test (as a class library project)

 

I want to be able to log messages in any of those layers using the same
log4net configuration file... 

Can you provide any suggestion for the right configuration? 

 

Regards,

Erlis


Re: Config log4net in n-tiear application Framework 2.0!

Posted by li nan <br...@gmail.com>.
You can create a common layer dll to be referenced by other all dll
files. Then in this common file, there is a public class:

public class Log{
  private log=ILog.Logger...........//Log4Net interface.

  //open the log interface from here
  public void DEBUG(string strlog)
  {
       log.Debug(strlog);
  }

  public void FATEL(string strlog)
  {
       log.Fater(strlog);
  }
  public void ERROR(string strlog)
  {
       log.Error(strlog);
  }
  ....... //Other interfaces..
}

2007/10/24, Erlis Vidal <Ev...@affiliated.ca>:
>
>
>
> Hi everyone!
>
>
>
> I want to configure log4net in order to use the same configuration file
> (with the watch option active) in my n-tier application!
>
>
>
> I have the following structure in my solution:
>
>
>
> Website (as a web application project)
>
> Business (as a class library project)
>
> Data (as a class library project)
>
> Test (as a class library project)
>
>
>
> I want to be able to log messages in any of those layers using the same
> log4net configuration file...
>
> Can you provide any suggestion for the right configuration?
>
>
>
> Regards,
>
> Erlis