Nope. Because the static GetLogger method is still being called BEFORE the
configuration of the assembly is done.
If you use:
private static readonly My.Network.ILogEx log =
My.Network.LogExManager.GetLogger(
"RepositoryNameDefinedViaRepositoryAttribute",
MethodBase.GetCurrentMethod().DeclaringType);
That just throws an exception of "{"Repository
[RepositoryNameDefinedViaRepositoryAttribute] is NOT defined."}".
Ok, here is what I finally got to work:
Add the log4net.Config.Repository("YourRepositoryName") attribute to the
AssemblyInfo class.
Create a custom STATIC Config() method that calls
log4net.Config.XmlConfigurator.ConfigureAndWatch(). Call that method before
you call the static GetLogger method and then log4net is configured. If you
use the assembly configuration attribute that attribute does NOT get called
before the static GetLogger method.
----- Original Message -----
From: "Ron Grabowski" <[EMAIL PROTECTED]>
To: "Log4NET User" <[email protected]>
Sent: Monday, April 17, 2006 8:53 PM
Subject: Re: Issue with Repositories and configuration...
What happens if you request the ILogEx instance from the My.Network
assembly (the My.Network repository) instead of letting log4net decide
what repository to create it from:
private static readonly My.Network.ILogEx log =
My.Network.LogExManager.GetLogger(
Assembly.GetAssembly(MethodBase.GetCurrentMethod().DeclaringType),
MethodBase.GetCurrentMethod().DeclaringType);
--- Hollywood <[EMAIL PROTECTED]> wrote:
I have an assembly that I want to use respositories for. It has the
following declared in the AssemblyInfo.cs file:
// We want this assembly to have a seperate logging repository to the
// rest of the application. We will configure this repository
seperatly.
[assembly: log4net.Config.Repository("My.Network")]
// Configure logging for this assembly using the
'My.Network.dll.log4net.config' file
[assembly: log4net.Config.XmlConfigurator(ConfigFileExtension =
"log4net.config", Watch = true)]
There is a class in this assembly that is defined as such:
public class NetLog
{
private static readonly My.Network.ILogEx log =
My.Network.LogExManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
}
And yes, I have a custom ILog, LogImpl and LogManager; and no they
are not
going away. The custom LogManager, LogExManager, is a duplicate of
LogManager except all instances of ILog are replaced by ILogEx.
LogExImpl
inherits from LogImpl and does ILogEx from ILog.
The issue is, if you put a break point at the 'private static
readonly
My.Network.ILogEx log' line, turn on the log4net.Internal.Debugging
in the
app's config file, then run it you will see that the static line gets
hit
first before the secondary repository is configured. This means that
the
"log" field is using the default repository, which was checked by
putting
break points in the various logging methods and checking the logger's
respository.
So whats up? What am I missing?
No offense, but I'd appreciate only answers from Niko or Ron, unless
you
have lots of experience with repositories in log4NET.
Thanks!