You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by John Price <jo...@gmail.com> on 2005/06/17 20:57:54 UTC

TypeInitializationException in log4net.Util.LogLog

We've got a system set up where a Windows service kicks off a number
of sort of "sub-services", each in their own AppDomains.  Each
sub-service is responsible for initializing the log4net system within
it's domain.  Everything works fine on developer machines (running
Windows XP), but when we try to deploy it to a production machine
(running Server 2K3) we get a TypeInitializationException (stack trace
below).
We're using log4net 1.2.9 beta.

I'm trying to get some log4net debug logs, but the machine that's
producing the errors isn't directly under my control, so it's tricky.

Has anyone seen this sort of behaviour before?

The exception was: 

System.Reflection.TargetInvocationException: Exception has been thrown
by the target of an invocation. --->
System.TypeInitializationException: The type initializer for
"D2L.Mail.MailService" threw an exception. --->
System.TypeInitializationException: The type initializer for
"log4net.Core.LoggerManager" threw an exception. --->
System.TypeInitializationException: The type initializer for
"log4net.Util.LogLog" threw an exception. --->
System.NullReferenceException: Object reference not set to an instance
of an object.

   at System.Configuration.ConfigurationSettings.GetConfig(String sectionName)
   at System.Diagnostics.DiagnosticsConfiguration.GetConfigTable()
   at System.Diagnostics.DiagnosticsConfiguration.Initialize()
   at System.Diagnostics.DiagnosticsConfiguration.get_IndentSize()
   at System.Diagnostics.TraceInternal.InitializeSettings()
   at System.Diagnostics.TraceInternal.get_Listeners()
   at System.Diagnostics.TraceInternal.WriteLine(String message)
   at System.Diagnostics.Trace.WriteLine(String message)
   at log4net.Util.LogLog.Error(String message, Exception exception)
   at log4net.Util.LogLog..cctor()

   --- End of inner exception stack trace ---

   at log4net.Util.LogLog.Debug(String message)
   at log4net.Core.LoggerManager..cctor()

   --- End of inner exception stack trace ---

   at log4net.Core.LoggerManager.GetLogger(Assembly
repositoryAssembly, String name)
   at log4net.LogManager.GetLogger(Type type)
   at D2L.Mail.MailService..cctor()

   --- End of inner exception stack trace ---

   --- End of inner exception stack trace ---

 
Server stack trace: 
   at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr,
Binder binder, Object[] args, CultureInfo culture, Object[]
activationAttributes)
   at System.Activator.CreateInstance(Type type, BindingFlags
bindingAttr, Binder binder, Object[] args, CultureInfo culture,
Object[] activationAttributes)
   at System.Activator.CreateInstance(String assemblyName, String
typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder,
Object[] args, CultureInfo culture, Object[] activationAttributes,
Evidence securityInfo, StackCrawlMark& stackMark)
   at System.Activator.CreateInstance(String assemblyName, String typeName)
   at System.AppDomain.CreateInstance(String assemblyName, String typeName)
   at System.AppDomain.CreateInstanceAndUnwrap(String assemblyName,
String typeName)
   at System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(MethodBase
mb, Object[] args, Object server, Int32 methodPtr, Boolean
fExecuteInContext, Object[]& outArgs)
   at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage
msg, Int32 methodPtr, Boolean fExecuteInContext)

Exception rethrown at [0]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage
reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&
msgData, Int32 type)
   at System.AppDomain.CreateInstanceAndUnwrap(String assemblyName,
String typeName)
   at D2L.Management.D2LService..ctor(ID2LInstance instance, ServiceInfo info)

Re: TypeInitializationException in log4net.Util.LogLog

Posted by John Price <jo...@gmail.com>.
I made this problem go away, and I think it has far more to do with
the .Net Tracing framework than it does with log4net, but I'm still
not sure why it was happening in the first place, so if anyone has any
ideas, they'd still be appreciated :)

Since we're kicking off each sub-service into its own app domain,
there isn't, by default, a configuration file set up for them.  You
can manually set the location of a config file, but we haven't needed
one, so we haven't bothered.  It looks like the exception was
happening when log4net was trying to write something out to Trace
during its initialization (so that when we were able to get DebugView
going on the machine, we didn't learn anything, since  the problem
happens as soon as log4net tries to output any debug messages).  The
Trace class tries to look up some config setting, and then has a fit
when there's no configuration file.  Creating an empty config file and
having the AppDomain setting point to it fixed the problem.

As I said, all this only seems to apply on our W2K3 boxes which are
running the same version of the framework (1.1 SP1) as our XP boxes,
which have never had this problem (even with debug enabled).

On 6/17/05, John Price <jo...@gmail.com> wrote:
> We've got a system set up where a Windows service kicks off a number
> of sort of "sub-services", each in their own AppDomains.  Each
> sub-service is responsible for initializing the log4net system within
> it's domain.  Everything works fine on developer machines (running
> Windows XP), but when we try to deploy it to a production machine
> (running Server 2K3) we get a TypeInitializationException (stack trace
> below).
> We're using log4net 1.2.9 beta.
> 
> I'm trying to get some log4net debug logs, but the machine that's
> producing the errors isn't directly under my control, so it's tricky.
> 
> Has anyone seen this sort of behaviour before?
> 
> The exception was:
> 
> System.Reflection.TargetInvocationException: Exception has been thrown
> by the target of an invocation. --->
> System.TypeInitializationException: The type initializer for
> "D2L.Mail.MailService" threw an exception. --->
> System.TypeInitializationException: The type initializer for
> "log4net.Core.LoggerManager" threw an exception. --->
> System.TypeInitializationException: The type initializer for
> "log4net.Util.LogLog" threw an exception. --->
> System.NullReferenceException: Object reference not set to an instance
> of an object.
> 
>    at System.Configuration.ConfigurationSettings.GetConfig(String sectionName)
>    at System.Diagnostics.DiagnosticsConfiguration.GetConfigTable()
>    at System.Diagnostics.DiagnosticsConfiguration.Initialize()
>    at System.Diagnostics.DiagnosticsConfiguration.get_IndentSize()
>    at System.Diagnostics.TraceInternal.InitializeSettings()
>    at System.Diagnostics.TraceInternal.get_Listeners()
>    at System.Diagnostics.TraceInternal.WriteLine(String message)
>    at System.Diagnostics.Trace.WriteLine(String message)
>    at log4net.Util.LogLog.Error(String message, Exception exception)
>    at log4net.Util.LogLog..cctor()
> 
>    --- End of inner exception stack trace ---
> 
>    at log4net.Util.LogLog.Debug(String message)
>    at log4net.Core.LoggerManager..cctor()
> 
>    --- End of inner exception stack trace ---
> 
>    at log4net.Core.LoggerManager.GetLogger(Assembly
> repositoryAssembly, String name)
>    at log4net.LogManager.GetLogger(Type type)
>    at D2L.Mail.MailService..cctor()
> 
>    --- End of inner exception stack trace ---
> 
>    --- End of inner exception stack trace ---
> 
> 
> Server stack trace:
>    at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly)
>    at System.Activator.CreateInstance(Type type, Boolean nonPublic)
>    at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr,
> Binder binder, Object[] args, CultureInfo culture, Object[]
> activationAttributes)
>    at System.Activator.CreateInstance(Type type, BindingFlags
> bindingAttr, Binder binder, Object[] args, CultureInfo culture,
> Object[] activationAttributes)
>    at System.Activator.CreateInstance(String assemblyName, String
> typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder,
> Object[] args, CultureInfo culture, Object[] activationAttributes,
> Evidence securityInfo, StackCrawlMark& stackMark)
>    at System.Activator.CreateInstance(String assemblyName, String typeName)
>    at System.AppDomain.CreateInstance(String assemblyName, String typeName)
>    at System.AppDomain.CreateInstanceAndUnwrap(String assemblyName,
> String typeName)
>    at System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(MethodBase
> mb, Object[] args, Object server, Int32 methodPtr, Boolean
> fExecuteInContext, Object[]& outArgs)
>    at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage
> msg, Int32 methodPtr, Boolean fExecuteInContext)
> 
> Exception rethrown at [0]:
>    at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage
> reqMsg, IMessage retMsg)
>    at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&
> msgData, Int32 type)
>    at System.AppDomain.CreateInstanceAndUnwrap(String assemblyName,
> String typeName)
>    at D2L.Management.D2LService..ctor(ID2LInstance instance, ServiceInfo info)
>