Someone had suggested this feature over a year ago:
http://issues.apache.org/jira/browse/LOG4NET-10
They suggested using the %v pattern. Which value do you want outputed:
Assembly.GetCallingAssembly()
Assembly.GetEntryAssembly()
Assembly.GetExecutingAssembly()
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):
%callingAssembly
%entryAssembly
%executingAssembly
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);
writer.Write(locationInformationType.Assembly.FullName);
}
}
A more clever way may be to extract the assembly name from the full qualified
ClassName string:
writer.Write(loggingEvent.LocationInformation.ClassName.Split(',')[1]);
The problem with the Split() method is that you will may get extra information
like versioning information.
----- Original Message ----
From: Milad Ershaghi <[EMAIL PROTECTED]>
To: [email protected]
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"?>
<configuration>
<configSections>
<section name="log4net"
type="System.Configuration.IgnoreSectionHandler"/>
</configSections>
<log4net>
<root>
<level value="ALL"/>
<appender-ref ref="LogFileAppender"/>
</root>
<appender name="LogFileAppender"
type="log4net.Appender.FileAppender">
<threshold value="ALL"/>
<file value="log4net.log"/>
<appendToFile value="false"/>
<immediateFlush value="true"/>
<lockingModel
type="log4net.Appender.FileAppender+ExclusiveLock" />
<layout type="log4net.Layout.PatternLayout">
<header value="[Start of
Execution] "/>
<footer value="[End of
Execution] "/>
<conversionPattern value="%date
[%thread] %-5level %logger [%property{NDC}] - %message%newline"/>
</layout>
</appender>
</log4net>
</configuration>
--
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?
Thanks
Sincerely,
Milad