I have two projects. One is a library and one is a host project.
In the library, I use Log4Net to push logs to a range of sources. I control logging by encapsulating the log4net calls inside a public helper class with static methods for logging. From the host project, I call the helper method defined in the library. (Maybe not the best architecture, but it's required to continue supporting an old in-house logging system in parallel)
At the moment, the host app is a console application. However, the library will be used by other web apps and services.
Log4Net settings (the loggers, a custom appender, and the custom renderer) are configured in the app.config file of the host. At some point before creating the Log4Net logger class (Manager.GetLogger) I use XML.Configure() to load the settings and the custom appender that I've defined is successfully created. Everything works at this point.
I've tried to add a new file appender. Since we always route logging through the Log.Verbose(object obj) instead of Log.Verbose(string msg) overloads, we had to create a custom renderer. The goal is to take that object and write a string that defines its contents.
I've used the fully qualified names to configure the custom renderer:
<log4net>
<renderer renderingclass="Core.Logging.Log4NetObjectLogger, Jazz.Core35, Version=2.0.0.23, Culture=neutral, PublicKeyToken=etcetcetc" renderedclass="System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77aetcetcetcetc" />
<root>
<level value="ALL" />
<appender-ref ref="AzureLogAnalyticsAppender"/>
<appender-ref ref="FileAppender"/>
</root>
Whatever I do, I cannot get rid of this error:
log4net:ERROR Could not instantiate class [].
System.ArgumentException: String cannot have zero length.
at System.Reflection.RuntimeAssembly.GetType(RuntimeAssembly assembly, String name, Boolean throwOnError, Boolean ignoreCase, ObjectHandleOnStack type)
at System.Reflection.RuntimeAssembly.GetType(String name, Boolean throwOnError, Boolean ignoreCase)
at log4net.Util.SystemInfo.GetTypeFromString(Assembly relativeAssembly, String typeName, Boolean throwOnError, Boolean ignoreCase)
at log4net.Util.SystemInfo.GetTypeFromString(String typeName, Boolean throwOnError, Boolean ignoreCase)
at log4net.Util.OptionConverter.InstantiateByClassName(String className, Type superClass, Object defaultValue)
log4net:ERROR Could not instantiate renderer [].
log4net:ERROR Could not instantiate class [].
System.ArgumentException: String cannot have zero length.
I've found a bunch of other people complaining about this same error but I didn't find a way to fix it. To get the fully-qualified type names, I wrote typeof(actualType).AssemblyQualifiedName() to the console and just pasted the result. Can anyone help?
I fixed this by camelCasing the xml attributes, e.g. renderingClass
in stead off renderingclass
.