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 "Gulati, Jay, GCM" <Ja...@rbsgc.com> on 2007/06/15 16:45:29 UTC

Reading config in business layer

Hi,

I have asp application  and writing new module in asp.net; how can I use
config settings for appender?  I like to use rollfileappender.
I module is class library and tried to add app.config and app.log4net
but it's not exe or web so can't read the configuration.
So my question is how to set xmlconfigurator to read config file?

Here is my test class and config file (simple)
using System;
using System.Collections.Generic;
using System.Text;

using log4net;
using log4net.Config;

[assembly: log4net.Config.XmlConfigurator(Watch = true)]
namespace busLayer
{
    public class Class1
    {
        private static readonly ILog log =
LogManager.GetLogger(typeof(Class1));

        public Class1()
        {
            log4net.Config.BasicConfigurator.Configure(new
log4net.Appender.RollingFileAppender());
        }

        public void MyLog(string message)
        {
            log.Debug(message);
        }
    }
}

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
  </configSections>
  <log4net>
    <appender name="RollingFileAppender"
type="log4net.Appender.RollingFileAppender">
      <file value="log.txt" />
      <appendToFile value="true" />
      <rollingStyle value="Size" />
      <maxSizeRollBackups value="10" />
      <maximumFileSize value="100KB" />
      <staticLogFileName value="true" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger
[%property{NDC}] - %message%newline" />
      </layout>
    </appender>

    <root>
      <level value="INFO" />
      <appender-ref ref="RollingFileAppender" />
    </root>
  </log4net>
</configuration>

Thank You,

-Jay Gulati



RE: Reading config in business layer

Posted by Dean Fiala <df...@celadonlabs.com>.
Easiest way is to tell it where the file is directly.  Add a static method
and call it from the global.asa application start.  Send the full file path
of the configuration file as an argument.  

public static void ConfigureLog4Net(string Log4NetConfigFile)
{

    XmlConfigurator.ConfigureAndWatch(New
System.IO.FileInfo(Log4NetConfigFile));

}

HTH,

Dean Fiala

Chief Technology Officer
Celadon Laboratories, Inc.
http://www.celadonlabs.com





-----Original Message-----
From: Gulati, Jay, GCM [mailto:Jay.Gulati@rbsgc.com] 
Sent: Friday, June 15, 2007 11:19 AM
To: Log4NET User; danny@jaguarsoftware.com
Subject: RE: Reading config in business layer

You are some what right but logging will be from .net business layer not
from asp but not sure how to set configuration in asp app as assembly can't
read config file. 
What I need is code required in asp app and I think c# code is same either
way.

Regards,
-Jay


-----Original Message-----
From: Price, Randall [mailto:randallp@vt.edu]
Sent: Friday, June 15, 2007 11:13 AM
To: Log4NET User; danny@jaguarsoftware.com
Subject: RE: Reading config in business layer


If I read your question correctly, it sounds like you want to consume
the log4net .NET assembly from a classic ASP page, not from an ASP.NET
page.  Is that correct?

If so, you need to follow some steps in order to use a .NET assembly
from a classic ASP page.

Here is a link that might help:

http://weblogs.asp.net/dneimke/archive/2004/01/31/65330.aspx


Randall Price

Secure Enterprise Technology Initiatives
Microsoft Implementation Group
Virginia Tech Information Technology
1700 Pratt Drive
Blacksburg, VA  24060

Email:  Randall.Price@vt.edu
Phone:  (540) 231-4396

-----Original Message-----
From: Gulati, Jay, GCM [mailto:Jay.Gulati@rbsgc.com] 
Sent: Friday, June 15, 2007 11:01 AM
To: Log4NET User; danny@jaguarsoftware.com
Subject: RE: Reading config in business layer

Thanks for you reply but not sure how to do it from asp application. I
mean how to configure in asp app; create type lib (tlb - regasm) for
log4net and then use it in asp app?



-----Original Message-----
From: Danny Gorton [mailto:danno@bushidosoftwareprojects.com] 
Sent: Friday, June 15, 2007 10:55 AM
To: Log4NET User
Subject: Re: Reading config in business layer


Jay,
  It should read the configuration file from the application that hosts 
your class assembly (DLL).  Assemblies do not load their own
configuration. Danny
 

-----------------------------------------
*******************************************************************
*

This e-mail is intended only for the addressee named above.
As this e-mail may contain confidential or privileged information, if
you are not the named addressee, you are not authorized to retain, read,
copy or disseminate this message or any part of it.

*******************************************************************
*


-----------------------------------------
*******************************************************************
*

This e-mail is intended only for the addressee named above.
As this e-mail may contain confidential or privileged information,
if you are not the named addressee, you are not authorized
to retain, read, copy or disseminate this message or any part of
it.

*******************************************************************
*



RE: Reading config in business layer

Posted by "Gulati, Jay, GCM" <Ja...@rbsgc.com>.
You are some what right but logging will be from .net business layer not
from asp but not sure how to set configuration in asp app as assembly
can't read config file. 
What I need is code required in asp app and I think c# code is same
either way.

Regards,
-Jay


-----Original Message-----
From: Price, Randall [mailto:randallp@vt.edu] 
Sent: Friday, June 15, 2007 11:13 AM
To: Log4NET User; danny@jaguarsoftware.com
Subject: RE: Reading config in business layer


If I read your question correctly, it sounds like you want to consume
the log4net .NET assembly from a classic ASP page, not from an ASP.NET
page.  Is that correct?

If so, you need to follow some steps in order to use a .NET assembly
from a classic ASP page.

Here is a link that might help:

http://weblogs.asp.net/dneimke/archive/2004/01/31/65330.aspx


Randall Price

Secure Enterprise Technology Initiatives
Microsoft Implementation Group
Virginia Tech Information Technology
1700 Pratt Drive
Blacksburg, VA  24060

Email:  Randall.Price@vt.edu
Phone:  (540) 231-4396

-----Original Message-----
From: Gulati, Jay, GCM [mailto:Jay.Gulati@rbsgc.com] 
Sent: Friday, June 15, 2007 11:01 AM
To: Log4NET User; danny@jaguarsoftware.com
Subject: RE: Reading config in business layer

Thanks for you reply but not sure how to do it from asp application. I
mean how to configure in asp app; create type lib (tlb - regasm) for
log4net and then use it in asp app?



-----Original Message-----
From: Danny Gorton [mailto:danno@bushidosoftwareprojects.com] 
Sent: Friday, June 15, 2007 10:55 AM
To: Log4NET User
Subject: Re: Reading config in business layer


Jay,
  It should read the configuration file from the application that hosts 
your class assembly (DLL).  Assemblies do not load their own
configuration. Danny
 

-----------------------------------------
*******************************************************************
*

This e-mail is intended only for the addressee named above.
As this e-mail may contain confidential or privileged information, if
you are not the named addressee, you are not authorized to retain, read,
copy or disseminate this message or any part of it.

*******************************************************************
*


-----------------------------------------
*******************************************************************
*

This e-mail is intended only for the addressee named above.
As this e-mail may contain confidential or privileged information,
if you are not the named addressee, you are not authorized
to retain, read, copy or disseminate this message or any part of
it.

*******************************************************************
*


RE: Reading config in business layer

Posted by "Price, Randall" <ra...@vt.edu>.
If I read your question correctly, it sounds like you want to consume
the log4net .NET assembly from a classic ASP page, not from an ASP.NET
page.  Is that correct?

If so, you need to follow some steps in order to use a .NET assembly
from a classic ASP page.

Here is a link that might help:

http://weblogs.asp.net/dneimke/archive/2004/01/31/65330.aspx


Randall Price

Secure Enterprise Technology Initiatives
Microsoft Implementation Group
Virginia Tech Information Technology
1700 Pratt Drive
Blacksburg, VA  24060

Email:  Randall.Price@vt.edu
Phone:  (540) 231-4396

-----Original Message-----
From: Gulati, Jay, GCM [mailto:Jay.Gulati@rbsgc.com] 
Sent: Friday, June 15, 2007 11:01 AM
To: Log4NET User; danny@jaguarsoftware.com
Subject: RE: Reading config in business layer

Thanks for you reply but not sure how to do it from asp application. I
mean how to configure in asp app; create type lib (tlb - regasm) for
log4net and then use it in asp app?



-----Original Message-----
From: Danny Gorton [mailto:danno@bushidosoftwareprojects.com] 
Sent: Friday, June 15, 2007 10:55 AM
To: Log4NET User
Subject: Re: Reading config in business layer


Jay,
  It should read the configuration file from the application that hosts 
your class assembly (DLL).  Assemblies do not load their own
configuration. Danny
 

-----------------------------------------
*******************************************************************
*

This e-mail is intended only for the addressee named above.
As this e-mail may contain confidential or privileged information,
if you are not the named addressee, you are not authorized
to retain, read, copy or disseminate this message or any part of
it.

*******************************************************************
*


Re: Reading config in business layer

Posted by Danny Gorton <da...@bushidosoftwareprojects.com>.
Put your log4net config in the web.config file.

Gulati, Jay, GCM wrote:
> Thanks for you reply but not sure how to do it from asp application. I
> mean how to configure in asp app; create type lib (tlb - regasm) for
> log4net and then use it in asp app?
>
>
>
> -----Original Message-----
> From: Danny Gorton [mailto:danno@bushidosoftwareprojects.com] 
> Sent: Friday, June 15, 2007 10:55 AM
> To: Log4NET User
> Subject: Re: Reading config in business layer
>
>
> Jay,
>   It should read the configuration file from the application that hosts 
> your class assembly (DLL).  Assemblies do not load their own
> configuration. Danny
>  
>
> -----------------------------------------
> *******************************************************************
> *
>
> This e-mail is intended only for the addressee named above.
> As this e-mail may contain confidential or privileged information,
> if you are not the named addressee, you are not authorized
> to retain, read, copy or disseminate this message or any part of
> it.
>
> *******************************************************************
> *
>
>
>
>   

RE: Reading config in business layer

Posted by "Gulati, Jay, GCM" <Ja...@rbsgc.com>.
Thanks for you reply but not sure how to do it from asp application. I
mean how to configure in asp app; create type lib (tlb - regasm) for
log4net and then use it in asp app?



-----Original Message-----
From: Danny Gorton [mailto:danno@bushidosoftwareprojects.com] 
Sent: Friday, June 15, 2007 10:55 AM
To: Log4NET User
Subject: Re: Reading config in business layer


Jay,
  It should read the configuration file from the application that hosts 
your class assembly (DLL).  Assemblies do not load their own
configuration. Danny
 

-----------------------------------------
*******************************************************************
*

This e-mail is intended only for the addressee named above.
As this e-mail may contain confidential or privileged information,
if you are not the named addressee, you are not authorized
to retain, read, copy or disseminate this message or any part of
it.

*******************************************************************
*


Re: Reading config in business layer

Posted by Danny Gorton <da...@bushidosoftwareprojects.com>.
Jay,
  It should read the configuration file from the application that hosts 
your class assembly (DLL).  Assemblies do not load their own configuration.
Danny
 
Gulati, Jay, GCM wrote:
>
> Hi,
>
> I have asp application  and writing new module in asp.net; how can I 
> use config settings for appender?  I like to use rollfileappender.
>
> I module is class library and tried to add app.config and app.log4net 
> but it's not exe or web so can't read the configuration.
>
> So my question is how to set xmlconfigurator to read config file?
>
> Here is my test class and config file (simple)
> using System;
> using System.Collections.Generic;
> using System.Text;
>
> using log4net;
> using log4net.Config;
>
> [assembly: log4net.Config.XmlConfigurator(Watch = true)]
> namespace busLayer
> {
>     public class Class1
>     {
>         private static readonly ILog log = 
> LogManager.GetLogger(typeof(Class1));
>
>         public Class1()
>         {
>             log4net.Config.BasicConfigurator.Configure(new 
> log4net.Appender.RollingFileAppender());
>         }
>
>         public void MyLog(string message)
>         {
>             log.Debug(message);
>         }
>     }
> }
>
> <?xml version="1.0" encoding="utf-8" ?>
> <configuration>
>   <configSections>
>     <section name="log4net" 
> type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
>   </configSections>
>   <log4net>
>     <appender name="RollingFileAppender" 
> type="log4net.Appender.RollingFileAppender">
>       <file value="log.txt" />
>       <appendToFile value="true" />
>       <rollingStyle value="Size" />
>       <maxSizeRollBackups value="10" />
>       <maximumFileSize value="100KB" />
>       <staticLogFileName value="true" />
>       <layout type="log4net.Layout.PatternLayout">
>         <conversionPattern value="%date [%thread] %-5level %logger 
> [%property{NDC}] - %message%newline" />
>       </layout>
>     </appender>
>
>     <root>
>       <level value="INFO" />
>       <appender-ref ref="RollingFileAppender" />
>     </root>
>   </log4net>
> </configuration>
>
> Thank You,
>
> -Jay Gulati
>
> ------------------------------------------------------------------------
>
> *
> *******************************************************************
> *
>
> This e-mail is intended only for the addressee named above.
> As this e-mail may contain confidential or privileged information,
> if you are not the named addressee, you are not authorized
> to retain, read, copy or disseminate this message or any part of
> it.
>
> *******************************************************************
> *
> *
>