|
From: Geoghegan, W. A (Willie) <wil...@in...> - 2010-09-13 16:37:38
|
Hello, I am currently evaluating Common.Logging. I have implemented a custom LoggerFactoryAdapter/Logger to wrap a logger that I wrote that logs via System.Diagnostics.TraceSource. Because the underlying logger is based on TraceSources, my factory does not require any additional configuration parameters. I created my logger factory adapter by subclassing from AbstractCachingLoggerFactoryAdapter and implementing the constructor which takes the NameValueCollection and also the CreateLogger method. When I configure Common.Logging (via the app.config file) to use my custom logger factory adapter, I get an exception that says: "Unable to create instance of type <my fully qualified logger factory adapter class>. Possible explanation is lack of zero arg and single arg NameValueCollection constructors." The inner exception says "No parameterless constructor defined for this object". I do have the NameValueCollection constructor, however, I do not have any configuration parameters in my app.config file (since my factory does not require any). I tried adding a zero arg constructor and got a compile error that the AbstractCachingLoggerFactoryAdapter does not contain a constructor that takes 0 arguments. I have worked around this by simply adding a dummy name/value pair to my factory adapter's configuration. It seems like it should be ok to have no configuration properties and that Common.Logging should be tolerant. Inside of LogManager.cs in BuildLoggerFactoryAdapterFromLogSettings around line 303, setting.Properties is tested. If it is not null and if setting.Properties.Count > 0, then the adapter is created via the "NameValueCollection" constructor. Otherwise, it is created via the zero arg constructor. Thanks. Willie Geoghegan. |