Loading...

log4net-user@logging.apache.org

[Prev] Thread [Next]  |  [Prev] Date [Next]

Re: Detached definition of layout Ron Grabowski Wed Nov 15 06:07:20 2006

Do you think extending a class and override one method is complicated? 

How do you think log4net should support this feature?

----- Original Message ----
From: Karel Kral <[EMAIL PROTECTED]>
To: Log4NET User <[EMAIL PROTECTED]>
Sent: Wednesday, November 15, 2006 2:55:31 AM
Subject: Re: Detached definition of layout

Thanks! It is no simple solution but thanks for it.
___________________________________________________
Karel Kral, vyvojar
ANETE, s.r.o.
Prostredi: VB.NET, VS2005, XP Pro/P4 3GHz, 2GB RAM
___________________________________________________

On 15.11.2006 2:09, Ron Grabowski wrote:
> If you're pattern doesn't change often or you have a standard company wide 
> pattern you could extend the PatternLayout class and tell the appender to use 
> that:
> 
> <appender name="FileAppender" type="log4net.Appender.FileAppender">
>  <file value="log.txt" /> 
>  <layout type="Company.Logging.StandardLayoutPattern, Company.Logging" />
> </appender>
> 
> You can apply a similiar idea to the FileAppender (or any other object) and 
> have it set default values:
> 
> <appender name="FileAppender" type="Company.Appender.FileAppender, Company">
> 
>  <file value="log.txt" /> 
> 
> </appender>
> 
> The Hierarchy repository supports setting repository level properties in the 
> config file. Someone could write a RepositoryPropertyPatternLayout that looks 
> for a property and uses that during the configuration process:
> 
> <log4net>
> <property key="defaultPattern" value="%date [%thread] %-5level " />
> <appender name="FileAppender" type="log4net.Appender.FileAppender">
>  <file value="log.txt" />  
>  <layout type="Company.RepositoryPropertyPatternLayout, Company" 
> value="defaultPattern" />
> </appender>
> <root>
>  <level value="ALL" />
>  <appender-ref ref="FileAppender" />
> </root>
> </log4net>
> 
> The current implementation of XmlHierarchyConfigurator.Configure configures 
> elements in the order they appear in the config file.
> 
> ----- Original Message ----
> From: Karel Kral <[EMAIL PROTECTED]>
> To: Log4NET User <[EMAIL PROTECTED]>
> Sent: Tuesday, November 14, 2006 3:28:43 AM
> Subject: Detached definition of layout
> 
> Hello, my log4net config gets to be a bit complicated. I have lot of
> appenders, which of them defines the same layout:
> 
>       <layout type="log4net.Layout.PatternLayout">
>         <conversionPattern value="%date [%thread] %-5level %-35.35logger
> [%-10.10property{NDC}] - %message%newline" />
>       </layout>
> 
> When I must to change definition of layout, the multiple definition of
> the same layout is problem - I must change the same thing on several places.
> 
> Is there any possibility to define "detached" layout in log4net config
> and in appender only set reference to it?
> 
> Example:
> <layout name="MySharedLayout", type="log4net.Layout.PatternLayout">
>    <conversionPattern value="%date [%thread] %-5level %-35.35logger
> [%-10.10property{NDC}] - %message%newline" />
>  </layout>
> 
> <appender name="Global.FileAppender"
> yype="log4net.Appender.RollingFileAppender">
> ...
> <layout-ref ref="MySharedLayout">
>     </appender>
> 
>