logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ITemplate <itempl...@hotmail.com>
Subject Re: How to get line number and file name in custom Appender?
Date Fri, 07 May 2010 11:37:03 GMT

Found out myself. In case other might wonder: The StackTrace is only
instantiated and processed if some configured layout pattern calls for it
(e.g. %method). The Appender eventually invoked this through specific
PatternConverter when the message is rendered. 

In the end this will be up to the Appender implementation so it seems. The
above logic is from the TextWriterAppender.

-- 
Werner



ITemplate wrote:
> 
> Hi,
> 
> Yes well I know that - but does log4net retrieve Stack information at all
> time? It would seem to me, that either it does (which is bad) or it
> inspects all possible layouts to determine if stack information is called
> for.
> 
> Does anyone know this?
> 
> -- 
> Werner
> 
> 
> Yuriy Taraday wrote:
>> 
>> StackTrace is internal .Net interface. Of course, .Net knows
>> everything about currently executing code unless this information was
>> wiped out by compiler/obfuscater/optimizer.
>> 
>> 
>> On Wed, May 5, 2010 at 12:24 AM, ITemplate <itemplate@hotmail.com> wrote:
>>>
>>> Hi Yuriy,
>>>
>>> Thanks for your reply. I gotta say, I was a bit surprised to see that
>>> log4net per default could write out stack information - is the
>>> stacktrace
>>> collected at all times? It would seem so...
>>>
>>> --
>>> Werner
>>>
>>>
>>>
>>>
>>> Yuriy Taraday wrote:
>>>>
>>>> http://logging.apache.org/log4net/release/sdk/log4net.Layout.PatternLayout.html
>>>> Note about caller location information.
>>>> The following patterns %type %file %line %method %location %class %C
>>>> %F %L %l %M all generate caller location information. Location
>>>> information uses the System.Diagnostics.StackTrace class to generate a
>>>> call stack. The caller's information is then extracted from this
>>>> stack.
>>>>
>>>> You should dig this way.
>>>> But you better should not log this. Use Stacks/Properties instead to
>>>> localize logging point in the source. It may not be as accurate as
>>>> StackTrace but it is appropriate and reliable.
>>>>
>>>> On Tue, May 4, 2010 at 5:50 PM, ITemplate <itemplate@hotmail.com>
>>>> wrote:
>>>>>
>>>>> Hi,
>>>>>
>>>>> Using a file appender, I can write the source code line number in my
>>>>> log
>>>>> file using "%line". But if I have a custom Appender with the
>>>>> "LoggingEvent"
>>>>> - where is that information stored and retrievable?
>>>>>
>>>>> --
>>>>> Werner
>>>>> --
>>>>> View this message in context:
>>>>> http://old.nabble.com/How-to-get-line-number-and-file-name-in-custom-Appender--tp28447536p28447536.html
>>>>> Sent from the Log4net - Users mailing list archive at Nabble.com.
>>>>>
>>>>>
>>>>
>>>>
>>>
>>> --
>>> View this message in context:
>>> http://old.nabble.com/How-to-get-line-number-and-file-name-in-custom-Appender--tp28447536p28452662.html
>>> Sent from the Log4net - Users mailing list archive at Nabble.com.
>>>
>>>
>> 
>> 
> 
> 

-- 
View this message in context: http://old.nabble.com/How-to-get-line-number-and-file-name-in-custom-Appender--tp28447536p28484939.html
Sent from the Log4net - Users mailing list archive at Nabble.com.


Mime
View raw message