Thanks a lot. I realized that I need className and method name in all log messages. If I try to use current approach reflection would be used to get both which is very costly. I would like to pass className and method name with each log message for example,
 
logger.Info(className, methodName, message);
 
I would use ClassName as const that would be static member and method Name as hardcoded for each method. This way cost is down and logmessage is more meaning ful and complete. I am liking extension option. Thanks. I will give extension a try.
-Raj

Nicko Cadell <[EMAIL PROTECTED]> wrote:
Raj,

Log4net can attempt to capture the location information from the caller.
It does this by generating an exception and inspecting the stack trace
within it. This can cause performance problems as generating a stack
trace is very expensive. Also the .net runtime does not guarantee that
the stack trace will be correct, the JIT can optimise away methods as it
sees fit. In a debug build the stack trace will mostly be accurate, but
in a release build it will likely not be accurate.

The following PatternLayout patterns extract location information:

%F Used to output the file name where the logging request was issued

%L Used to output the line number from where the logging request was
issued

%M Used to output the method name where the logging request was issued

%C
Used to output the fully qualified class name of the caller issuing the
logging request. This conversion specifier can be optionally followed by
precision specifier, that is a decimal constant in brackets.
If a precision specifier is given, then only the corresponding number of
right most components of the class name will be printed. By default the
class name is output in fully qualified form.
For example, for the class name "log4net.Layout.PatternLayout", the
pattern %C{1} will output "PatternLayout".


If you don't want to incur the performance overhead of generating the
stack trace for each log message then you will need to pass the method
name into the log method. You can do this by incorporating it into the
message that is logged or you can write an extension that allows you to
change the API your program uses to talk to log4net.

In the log4net download have a look at the
extensions\net\1.0\log4net.Ext.EventID extension. This adds an
additional parameter to all the log methods to take an int which is the
EventID. In your case you would want to pass an additional string for
the method name. You could store this string in an event property and
then use the %P{propname} pattern to include the value in the output.

Nicko


> -----Original Message-----
> From: rajesh patel [mailto:[EMAIL PROTECTED]
> Sent: 24 July 2004 06:26
> To: [email protected]
> Subject: logging method name and formatting method name
>
> Hi,
> I am new to Log4net. I am seriously thinking about using
> this logging utility but I am missing one big expectation.
> I would like to add method name in the log message. This
> way I know which method logged message. I saw class
> LocationInfo.cs that has MethodName property. This means we
> should be able to log method name in output log text. Can
> someone explain how can I do that? Also I would like to
> format how the method name can be formatted? I mean only
> actual method name or fully qualified name etc.
>
> I would appreciate the response.
>
> -Raj
>
> ________________________________
>
> Do you Yahoo!?
> Yahoo! Mail
> > s.yahoo.com/new_mail/static/efficiency.html> - 50x more
> storage than other providers!
>


Do you Yahoo!?
Yahoo! Mail - 50x more storage than other providers!

Reply via email to