logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Karel Kral <kral.k...@volny.cz>
Subject Re: Detached definition of layout
Date Wed, 15 Nov 2006 14:11:54 GMT
<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" />

I'm sorry, You example would satisfy what I need. So I must to write
CustomisedLayoutPattern, it would to be realisable. My question is how
to access property "defaultPattern" from my CustomisedLayoutPattern code?
___________________________________________________
Karel Kral, vyvojar
ANETE, s.r.o.
Prostredi: VB.NET, VS2005, XP Pro/P4 3GHz, 2GB RAM
___________________________________________________

On 15.11.2006 15:04, Karel Kral wrote:
> No, extending class is not complicated, I have already done some
> Appenders etc. I can create the descendant of the PatternLayout with
> hard-wired pattern without problem.
> 
> But what I can't imagine is how to create PatternLayout descendant in
> the manner of my original question. Layout, which is "detached", which
> is configurable from XML and is referable in the same way as appenders.
> Example "MySharedLayout" bellow. Is this realizable by me?
> 
> <layout type="Company.Logging.CustomisedLayoutPattern, Company.Logging"
> name="MySharedLayout">
>   <conversionPattern value="%date [%thread] %-5level %-35.35logger
> [%-10.10property{NDC}] - %message%newline" />
> </layout>
> 
> <appender name="Global.FileAppender"
> type="log4net.Appender.RollingFileAppender">
> <layout-ref ref="MySharedLayout">
> </appender>
> 
> ___________________________________________________
> Karel Kral, vyvojar
> ANETE, s.r.o.
> Prostredi: VB.NET, VS2005, XP Pro/P4 3GHz, 2GB RAM
> ___________________________________________________
> 
> On 15.11.2006 13:35, Ron Grabowski wrote:
>> 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 <kral.konf@volny.cz>
>> To: Log4NET User <log4net-user@logging.apache.org>
>> 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 <kral.konf@volny.cz>
>>> To: Log4NET User <log4net-user@logging.apache.org>
>>> 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"
>>> type="log4net.Appender.RollingFileAppender">
>>> ...
>>> <layout-ref ref="MySharedLayout">
>>>     </appender>
>>>
>>>
>>
>>
>>
>>
> 
> 

Mime
View raw message