예제 #1
0
        /// <summary>
        /// Configure the application logging service.
        /// </summary>
        public static IServiceCollection AddLogger(this IServiceCollection services,
                                                   LoggerOptions options)
        {
            var logger = new LogAggregator();

            logger.Initialize(options.Level);
            logger.AllowedTypes = options.LoggerType;

            if (options.LoggerType.HasFlag(LoggerTypes.DebugOutput))
            {
                var debugLogger = new DebugOuputLogger();
                debugLogger.Initialize(options.Level);
                logger.AddLogger(debugLogger, LoggerTypes.DebugOutput);
            }

            if (options.LoggerType.HasFlag(LoggerTypes.File))
            {
                var fileLogger = new FileLogger();
                fileLogger.Initialize(options.Level, options.LogFilePath, options.UseFileCompression);
                logger.AddLogger(fileLogger, LoggerTypes.File);
            }
            services.AddSingleton <ILogger>(logger);
            return(services);
        }