Example #1
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>();
        }
 public void Fatal(string message, Exception exception = null, object additionalData = null)
 {
     StaticSimpleLogger.Fatal(message, exception, this.RequestKey.Value, additionalData);
 }
 public void Verbose(string message, object additionalData = null)
 {
     StaticSimpleLogger.Verbose(message, this.RequestKey.Value, additionalData);
 }
 public void Debug(string controller, string operation, string message, object additionalData = null)
 {
     StaticSimpleLogger.Debug(controller, operation, message, this.RequestKey.Value, additionalData);
 }
 public void Fatal(string controller, string operation, string message, Exception exception, object additionalData = null)
 {
     StaticSimpleLogger.Fatal(controller, operation, message, exception, this.RequestKey.Value, additionalData);
 }