logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ron Grabowski <rongrabow...@yahoo.com>
Subject Re: Possible To Name Log File After Assembly?
Date Tue, 07 Nov 2006 04:29:18 GMT

Someone had suggested this feature over a year ago:


They suggested using the %v pattern. Which value do you want outputed:


Do you have any suggestions for what the other useful names would be? Since these patterns
probably won't get used as often as some of the other patterns, I think its ok to use longer,
more descriptive names (I don't know if these would give you log4net information or information
from your application):


LocationInformation doesn't store the System.Type of the LoggingEvent (for serialization reasons?).
One solution would be to write a small helper function that translates the ClassName string
into the appropriate Type (or Assembly):

// untested
public class CallingAssemblyPatternConverter : PatternLayoutConverter 
 override protected void Convert(TextWriter writer, LoggingEvent loggingEvent)
  Type locationInformationType = getTypeForClassNameloggingEvent.LocationInformation.ClassName);

A more clever way may be to extract the assembly name from the full qualified ClassName string:


The problem with the Split() method is that you will may get extra information like versioning

----- Original Message ----

From: Milad Ershaghi <mershaghi@esri.com>

To: log4net-user@logging.apache.org

Sent: Monday, November 6, 2006 9:29:58 PM

Subject: Possible To Name Log File After Assembly?

Dear Community,

I was wondering if it is possible to name a log file after an assembly

via the config file. Here is my config file:


<?xml version="1.0" encoding="utf-8"?>



        <section name="log4net"





            <level value="ALL"/>

            <appender-ref ref="LogFileAppender"/>


        <appender name="LogFileAppender"


            <threshold value="ALL"/>

            <file value="log4net.log"/>

            <appendToFile value="false"/>

            <immediateFlush value="true"/>


type="log4net.Appender.FileAppender+ExclusiveLock" />

            <layout type="log4net.Layout.PatternLayout">

                <header value="[Start of


                <footer value="[End of


                <conversionPattern value="%date

[%thread] %-5level %logger [%property{NDC}] - %message%newline"/>






Would it be possible to replace "log4net.log" with some other parameter

that would refer to the assembly name say in braces and then add on a

file extension. For example:

<file value="{AssemblyName}.log"/>

Or is there some other way to accomplish this?




View raw message