コード例 #1
0
        public static Logger CreateLogger(string env, string app, VersionInfo version, AppCfg cfg = null)
        {
            var c = new LoggerConfiguration()
                    .WriteTo.Console(LogEventLevel.Information);

            if (cfg?.AppInsightsKey != null)
            {
                c.WriteTo.ApplicationInsights(new TelemetryConfiguration(cfg.AppInsightsKey), TelemetryConverter.Traces, cfg.LogLevel);
            }

            if (cfg != null)
            {
                c = c.ConfigureSeq(cfg);
            }

            var log = c.YtEnrich(env, app, version.Version)
                      .MinimumLevel.ControlledBy(new LoggingLevelSwitch(cfg?.LogLevel ?? LogEventLevel.Debug))
                      .CreateLogger();

            Log.Logger = log;
            return(log);
        }