コード例 #1
0
        public static IHostBuilder UseSerilog(this IHostBuilder builder, string[] args)
        {
            var configuration = new ConfigurationBuilder()
                                .AddJsonFile("appsettings.json", false, true)
                                .AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")}.json", true, true)
                                .AddEnvironmentVariables()
                                .AddCommandLine(args)
                                .Build();

            var appName   = configuration.GetValue <string>(APP_NAME_SECTION);
            var appId     = configuration.GetValue <string>(APP_ID_SECTION);
            var serverUrl = configuration.GetValue <string>(SEQ_URL_SECTION);
            var apiKey    = configuration.GetValue <string>(SEQ_APIKEY_SECTION);

            var levelSwitch = new LoggingLevelSwitch();

            Log.Logger = new LoggerConfiguration().ReadFrom
                         .Configuration(configuration)
                         .MinimumLevel.ControlledBy(levelSwitch)
                         .Enrich.FromLogContext()
                         .Enrich.WithMachineName()
                         .Enrich.WithThreadId()
                         .Enrich.WithClientIp()
                         .Enrich.WithSpan()
                         .Enrich.WithProperty("ApplicationName", string.IsNullOrWhiteSpace(appId) ? string.IsNullOrWhiteSpace(appName) ? "unknown" : appName : appId)
                         .WriteTo.Console()
                         .WriteTo.Seq(string.IsNullOrWhiteSpace(serverUrl) ? "http://seq" : serverUrl, apiKey: apiKey, controlLevelSwitch: levelSwitch)
                         .CreateLogger();

            SerilogHostBuilderExtensions.UseSerilog(builder);

            return(builder);
        }
コード例 #2
0
        public static IHostBuilder UseSerilog(this IHostBuilder builder)
        {
            var configuration = new ConfigurationBuilder().Configuration();

            Log.Logger = new LoggerConfiguration().ReadFrom.Configuration(configuration).CreateLogger();

            SerilogHostBuilderExtensions.UseSerilog(builder);

            return(builder);
        }
コード例 #3
0
        public static IHostBuilder UseSerilog(this IHostBuilder builder)
        {
            var configuration = new ConfigurationBuilder()
                                .AddJsonFile("appsettings.Development.json")
                                .AddJsonFile("appsettings.json")
                                .AddEnvironmentVariables()
                                .Build();

            Log.Logger = new LoggerConfiguration().ReadFrom.Configuration(configuration).CreateLogger();
            SerilogHostBuilderExtensions.UseSerilog(builder);
            return(builder);
        }
コード例 #4
0
 public static IHostBuilder UseSerilog(this IHostBuilder builder, Action <HostBuilderContext, LoggerConfiguration> configureLogger, bool preserveStaticLogger = false, bool writeToProviders = false)
 {
     return(SerilogHostBuilderExtensions.UseSerilog(builder, configureLogger, preserveStaticLogger, writeToProviders));
 }
コード例 #5
0
 public static IHostBuilder UseSerilog(this IHostBuilder builder, ILogger logger = null, bool dispose = false, LoggerProviderCollection providers = null)
 {
     return(SerilogHostBuilderExtensions.UseSerilog(builder, logger, dispose, providers));
 }