public static void SetupSerilog(
            this IServiceCollection services,
            string domain,
            string application,
            LoggerSettings settings,
            IEnumerable <string> ignoredRoutes)
        {
            var loggerBuilder = new LoggerBuilder();

            Log.Logger = loggerBuilder
                         .UseSuggestedSetting(domain, application)
                         .SetupSeq(settings?.SeqOptions)
                         .SetupSplunk(settings?.SplunkOptions)
                         .BuildLogger();

            if (settings?.DebugEnabled ?? false)
            {
                loggerBuilder.EnableDebug();
            }

            var config = new SerilogConfiguration
            {
                InformationTitle    = settings?.TitlePrefix + CommunicationLogger.DefaultInformationTitle,
                ErrorTitle          = settings?.TitlePrefix + CommunicationLogger.DefaultErrorTitle,
                Blacklist           = settings?.JsonBlacklist,
                RequestKeyProperty  = RequestKeyServiceExtension.RequestKeyHeaderName,
                AccountIdProperty   = AccountIdServiceExtension.AccountIdHeaderName,
                TimeElapsedProperty = TimeElapsedServiceExtension.TimeElapsedHeaderName,
                IgnoredRoutes       = ignoredRoutes
            };

            services.SetupSerilog(config);
        }
Beispiel #2
0
        public static void SetupSerilog(
            this IServiceCollection services,
            string domain,
            string application,
            LoggerSettings settings,
            List <string> ignoredRoutes)
        {
            var loggerBuilder = new LoggerBuilder();

            if (settings?.NewRelicOptions?.Enabled == true && string.IsNullOrWhiteSpace(settings?.NewRelicOptions?.LicenseKey))
            {
                settings.NewRelicOptions.LicenseKey = Environment.GetEnvironmentVariable("NEW_RELIC_LICENSE_KEY");
            }

            Log.Logger = loggerBuilder
                         .UseSuggestedSetting(domain, application)
                         .SetupSeq(settings?.SeqOptions)
                         .SetupSplunk(settings?.SplunkOptions)
                         .SetupNewRelic(settings?.NewRelicOptions)
                         .SetupDataDog(settings?.DataDogOptions)
                         .BuildLogger();

            if (settings?.DebugEnabled ?? false)
            {
                loggerBuilder.EnableDebug();
            }

            var config = new SerilogConfiguration
            {
                Version              = Api.ApiSettings.BuildVersion,
                InformationTitle     = settings?.TitlePrefix + CommunicationLogger.DefaultInformationTitle,
                ErrorTitle           = settings?.TitlePrefix + CommunicationLogger.DefaultErrorTitle,
                BlacklistRequest     = settings?.GetJsonBlacklistRequest(),
                BlacklistResponse    = settings?.JsonBlacklistResponse,
                HeaderBlacklist      = settings?.HeaderBlacklist,
                QueryStringBlacklist = settings?.QueryStringBlacklist,
                RequestKeyProperty   = RequestKeyServiceExtension.RequestKeyHeaderName,
                AccountIdProperty    = AccountIdServiceExtension.AccountIdHeaderName,
                TimeElapsedProperty  = TimeElapsedServiceExtension.TimeElapsedHeaderName,
                IgnoredRoutes        = ignoredRoutes
            };

            StaticSimpleLogger.UpdateVersion(Api.ApiSettings.BuildVersion);
            StaticSimpleLogger.UpdateEnvironment(EnvironmentUtility.GetCurrentEnvironment());

            services.SetupSerilog(config);
            services.AddScoped <ISimpleLogger, SimpleLogger>();
        }