This project is read-only.

Trying to inject ILogger into a constructor results in an error .. I need to log something!

Topics: Writing modules
May 15, 2013 at 6:22 PM
Edited May 15, 2013 at 6:23 PM
public class Service : IService {

        public Service(ILogger logger) {
            Logger = logger;

        public ILogger Logger { get; set; }

When I do this, I get this error

Sequence contains no elements on Line 74

Line 73:             var loggerFactory = context.Resolve<ILoggerFactory>();
Line 74:             var containingType = parameters.TypedAs<Type>();
Line 75:             return loggerFactory.CreateLogger(containingType);
Line 76:         }
What am I doing wrong?

Is there anywhere where I set the Type to be used as ILogger?
May 15, 2013 at 6:28 PM
The loggers are not injected like other services, in the constructor, but as a property instead. The only change you need is to assign a NullLogger.Instance to the property from the constructor:
public Service() {
        Logger = NullLogger.Instance;

public ILogger Logger { get; set; }
May 16, 2013 at 12:00 PM
Ah yes. Thank you.

How do I switch the logging level of the site from Error, to Information, to All, for example?
May 16, 2013 at 12:26 PM
The default logger uses Log4Net, so I think you should be able to configure that with log4net.config in the Config folder.