コード例 #1
0
        private static void ConfigureLogger()
        {
            var minLogLevel = "Debug";
            var maxLogLevel = "Fatal";

            LoggerConfiguration.ConfigureLogger(minLogLevel, maxLogLevel);
        }
コード例 #2
0
        /// <summary>
        ///     Configures Serilog as logger, adds it to the service list and configures Serilog from configuration
        /// </summary>
        /// <param name="hostBuilder"></param>
        /// <returns></returns>
        public static IHostBuilder UseSerilogWithConfiguration(this IHostBuilder hostBuilder)
        {
            return(hostBuilder.ConfigureServices((h, collection) =>
            {
                var loggerConfiguration = new LoggerConfiguration();
                loggerConfiguration.ConfigureLogger(h.Configuration);

                Logger logger = loggerConfiguration.CreateLogger();
                Log.Logger = logger;

                collection.AddSingleton(services => (ILoggerFactory) new SerilogLoggerFactory(null, true));
                collection.AddSingleton(p => Log.Logger);
            }));
        }