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 "João Felipe S. Pinto" <jo...@jfsp.net> on 2008/03/15 02:39:27 UTC

ASP.NET 2.0 C# - Logging issues with multi layer app.

Hello all,

Hope this is an easy stuff to solve due to a newbies misconfig step or 
something.

lemme introduce better my problem

i'm developing a 2-tier app.

tier 1 : Web Site
tier 2: Data Access Layer

i have the log4net config part on the web.config it self.
here it is :
================================================================================
<configuration>
...
<configSections>
    <section name="log4net" 
type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
....
<log4net>
        <appender name="RollingLogFileAppender" 
type="log4net.Appender.RollingFileAppender">
            <file value="..\logs\log-file.txt" />
            <appendToFile value="true" />
            <datePattern value="yyyyMMdd" />
            <rollingStyle value="Date" />
            <layout type="log4net.Layout.PatternLayout">
                <conversionPattern value="%-5p %d %5rms %-22.22c{1} 
%-18.18M - %m%n" />
            </layout>
        </appender>
        <root>
            <level value="ALL" />
            <appender-ref ref="RollingLogFileAppender" />
        </root>
    </log4net>
...
<configuration>
================================================================================
as well as the entry at global asax
================================================================================
void Application_Start(object sender, EventArgs e)
    {
        log4net.Config.XmlConfigurator.Configure();
    }
================================================================================

with this done i can perfectly log from the Tier 1(Web Site) here is an 
example:
================================================================================
public partial class UsersList : System.Web.UI.Page
{
  ....
     ILog log = 
LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
....
    log.Debug("Calling userDAO.GetAllUsers()");
....
}
================================================================================
but when i try logging on the Tier 2, doesn't do anything at all, not 
even an error.
================================================================================
public partial class userDAO : DAObase
    {
        private static readonly ILog log = 
LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
.....
        public DataTable GetAllUsers(out string ErrMsg)
        {
            ErrMsg = String.Empty;
            cmd.CommandText = _queryGetAllUsers;

            log.Debug(MethodBase.GetCurrentMethod().Name + ":" + 
"Connecting to DB");

            cmd.Connection = conn.GetConn();
    .....
         }
......
}
================================================================================

-- 
::::: Now Playing: (Winamp is not active ;-)

João Felipe Santoro Pinto<jo...@jfsp.net>

For more Info check my vCard attached


Re: ASP.NET 2.0 C# - Logging issues with multi layer app.

Posted by li nan <br...@gmail.com>.
I suggest you create a wrapper for the log4net.

class wrapper
{
   log4net.ILog log = .....


}

all of other dll include this wrapper, then it can be used in all other layers.

2008/3/17, Simon Tamman <sp...@wayfarer.co.uk>:
> I'm not exactly a Log4Net expert but the call in the 2nd tier is static, this means if the userDAO object is ever referenced
> before log4net.Config.XmlConfigurator.Configure(); is run then it will try to get the ILog before it is ready.
> Have you tried making it non-static?
>
> Kind Regards
>
> Simon
>
> -----Original Message-----
> From: "João Felipe S. Pinto" [mailto:joao@jfsp.net]
> Sent: 15 March 2008 01:39
> To: log4net-user@logging.apache.org
> Subject: ASP.NET 2.0 C# - Logging issues with multi layer app.
>
> Hello all,
>
> Hope this is an easy stuff to solve due to a newbies misconfig step or something.
>
> lemme introduce better my problem
>
> i'm developing a 2-tier app.
>
> tier 1 : Web Site
> tier 2: Data Access Layer
>
> i have the log4net config part on the web.config it self.
> here it is :
> ================================================================================
> <configuration>
> ...
> <configSections>
>    <section name="log4net"
> type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" /> </configSections> ....
> <log4net>
>        <appender name="RollingLogFileAppender"
> type="log4net.Appender.RollingFileAppender">
>            <file value="..\logs\log-file.txt" />
>            <appendToFile value="true" />
>            <datePattern value="yyyyMMdd" />
>            <rollingStyle value="Date" />
>            <layout type="log4net.Layout.PatternLayout">
>                <conversionPattern value="%-5p %d %5rms %-22.22c{1} %-18.18M - %m%n" />
>            </layout>
>        </appender>
>        <root>
>            <level value="ALL" />
>            <appender-ref ref="RollingLogFileAppender" />
>        </root>
>    </log4net>
> ...
> <configuration>
> ================================================================================
> as well as the entry at global asax
> ================================================================================
> void Application_Start(object sender, EventArgs e)
>    {
>        log4net.Config.XmlConfigurator.Configure();
>    }
> ================================================================================
>
> with this done i can perfectly log from the Tier 1(Web Site) here is an
> example:
> ================================================================================
> public partial class UsersList : System.Web.UI.Page {
>  ....
>     ILog log =
> LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
> ....
>    log.Debug("Calling userDAO.GetAllUsers()"); ....
> }
> ================================================================================
> but when i try logging on the Tier 2, doesn't do anything at all, not even an error.
> ================================================================================
> public partial class userDAO : DAObase
>    {
>        private static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
> .....
>        public DataTable GetAllUsers(out string ErrMsg)
>        {
>            ErrMsg = String.Empty;
>            cmd.CommandText = _queryGetAllUsers;
>
>            log.Debug(MethodBase.GetCurrentMethod().Name + ":" + "Connecting to DB");
>
>            cmd.Connection = conn.GetConn();
>    .....
>         }
> ......
> }
> ================================================================================
>
> --
> ::::: Now Playing: (Winamp is not active ;-)
>
> João Felipe Santoro Pinto<jo...@jfsp.net>
>
> For more Info check my vCard attached
>
>
>
> --------------------------------------------------------------------
> *** This email may contain confidential information and/or copyright material.  This email is intended for the use of the addressee only. Any unauthorized use may be unlawful.  If you receive this email by mistake, please advise the sender immediately by using the reply facility in your email software.  You should be aware that the contents of this email may be monitored to ensure compliance with the Wayfarer Transit Systems Ltd IT User policy.  Wayfarer Transit Systems Limited, Registered in England & Wales no: 01232487. Registered Office:10 Willis Way, Fleets Industrial Estate, Poole, Dorset, BH15 3SS. ***
>

RE: ASP.NET 2.0 C# - Logging issues with multi layer app.

Posted by Simon Tamman <sp...@wayfarer.co.uk>.
I'm not exactly a Log4Net expert but the call in the 2nd tier is static, this means if the userDAO object is ever referenced
before log4net.Config.XmlConfigurator.Configure(); is run then it will try to get the ILog before it is ready.
Have you tried making it non-static?

Kind Regards

Simon

-----Original Message-----
From: "João Felipe S. Pinto" [mailto:joao@jfsp.net] 
Sent: 15 March 2008 01:39
To: log4net-user@logging.apache.org
Subject: ASP.NET 2.0 C# - Logging issues with multi layer app.

Hello all,

Hope this is an easy stuff to solve due to a newbies misconfig step or something.

lemme introduce better my problem

i'm developing a 2-tier app.

tier 1 : Web Site
tier 2: Data Access Layer

i have the log4net config part on the web.config it self.
here it is :
================================================================================
<configuration>
...
<configSections>
    <section name="log4net" 
type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" /> </configSections> ....
<log4net>
        <appender name="RollingLogFileAppender" 
type="log4net.Appender.RollingFileAppender">
            <file value="..\logs\log-file.txt" />
            <appendToFile value="true" />
            <datePattern value="yyyyMMdd" />
            <rollingStyle value="Date" />
            <layout type="log4net.Layout.PatternLayout">
                <conversionPattern value="%-5p %d %5rms %-22.22c{1} %-18.18M - %m%n" />
            </layout>
        </appender>
        <root>
            <level value="ALL" />
            <appender-ref ref="RollingLogFileAppender" />
        </root>
    </log4net>
...
<configuration>
================================================================================
as well as the entry at global asax
================================================================================
void Application_Start(object sender, EventArgs e)
    {
        log4net.Config.XmlConfigurator.Configure();
    }
================================================================================

with this done i can perfectly log from the Tier 1(Web Site) here is an
example:
================================================================================
public partial class UsersList : System.Web.UI.Page {
  ....
     ILog log =
LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
....
    log.Debug("Calling userDAO.GetAllUsers()"); ....
}
================================================================================
but when i try logging on the Tier 2, doesn't do anything at all, not even an error.
================================================================================
public partial class userDAO : DAObase
    {
        private static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
.....
        public DataTable GetAllUsers(out string ErrMsg)
        {
            ErrMsg = String.Empty;
            cmd.CommandText = _queryGetAllUsers;

            log.Debug(MethodBase.GetCurrentMethod().Name + ":" + "Connecting to DB");

            cmd.Connection = conn.GetConn();
    .....
         }
......
}
================================================================================

--
::::: Now Playing: (Winamp is not active ;-)

João Felipe Santoro Pinto<jo...@jfsp.net>

For more Info check my vCard attached



--------------------------------------------------------------------
*** This email may contain confidential information and/or copyright material.  This email is intended for the use of the addressee only. Any unauthorized use may be unlawful.  If you receive this email by mistake, please advise the sender immediately by using the reply facility in your email software.  You should be aware that the contents of this email may be monitored to ensure compliance with the Wayfarer Transit Systems Ltd IT User policy.  Wayfarer Transit Systems Limited, Registered in England & Wales no: 01232487. Registered Office:10 Willis Way, Fleets Industrial Estate, Poole, Dorset, BH15 3SS. ***