Error Logging with Custom Module

Topics: Writing modules
Aug 11, 2015 at 7:27 PM
I am trying to use the logging facilities with Orchard but I must be missing something. I am using the ILogger interface and have initially set it to NullLogger as seen in much of the code within Orchard. However, that needs to be replace by a real logger before anything is actually written to a file. Are there any examples of how and where is that done?
Aug 11, 2015 at 9:19 PM
Edited Aug 11, 2015 at 9:19 PM
Do you have a property of type ILogger?
protected ILogger Logger { get; set; }
The instance of the Logger gets injected by Autofac. The implementation is in an autofac module (Orchard.Logging.LoggingModule).
Aug 11, 2015 at 10:49 PM
Yes, I have implement that code and set the initial value to Logger = NullLogger.Instance. However at run time Autofac does not appear to be injecting the real logger. When I run the code or when I step through the debugger it is always using the NullLogger.

I wonder if Autofac is having trouble injecting into the Dynamic Form Element I am writing.
Aug 11, 2015 at 11:00 PM
Make sure that the Logger property s public, not protected. Otherwise Autofac won't be able to property-inject it.
Aug 12, 2015 at 8:44 AM
That make sense, but why is the ILogger in the BlogController protected?
Aug 12, 2015 at 9:27 AM
I'd say that would be a bug. Unless you can see in the debugger that it references an actual logger implementation other than the NullLogger instance?