I have been given this code
public static class Logger
{
public static Func<ILogger> LoggerFactory;
private static readonly Lazy<ILogger> _log = new Lazy<ILogger>(LoggerFactory);
public static ILogger Instance
{
get
{
return _log.Value;
}
public static ILogger ConfigureLogging(string AppName, Version AppVersion)
{
// stuff
}
}
}
This static class is used in the application:
Logger.LoggerFactory = () => Logger.ConfigureLogging(AppName, AppVersion);
Logger.Instance.Information("Starting application");
I would expect the first row to set the LoggerFactory; however on the first attempt of writing to the log, an exception has thrown because the static Func LoggerFactory hasn't been set yet.
What's wrong with this code?
Thanks