Exemple #1
0
#pragma warning disable CA1801 // Review unused parameters -- required for other build configuration
#endif
        private static void ConfigureLogging(HostBuilderContext builderContext, ILoggingBuilder loggingBuilder)
#if MINIMAL_BUILD
#pragma warning restore CA1801 // Review unused parameters
#endif
        {
            loggingBuilder.AddFilter(
                (category, level) => level >= LogLevel.Warning ||
                (level >= LogLevel.Information && !category.StartsWith("Microsoft.AspNetCore.", StringComparison.OrdinalIgnoreCase)));

#if !MINIMAL_BUILD
            if (Journal.IsSupported)
            {
                loggingBuilder.AddJournal(options =>
                {
                    options.SyslogIdentifier = builderContext.HostingEnvironment.ApplicationName;
                });
            }
#endif

#if !MINIMAL_BUILD
            if (builderContext.Configuration.GetValue <bool>("ForceConsoleLogging") ||
                !Journal.IsAvailable)
#endif
            {
                loggingBuilder.AddSystemdConsole(options =>
                {
                    options.IncludeScopes   = true;
                    options.TimestampFormat = "yyyy-MM-ddTHH:mm:ss.fffffffzzz \""
                                              + Environment.MachineName
                                              + "\" \""
                                              + builderContext.HostingEnvironment.ApplicationName
                                              + ":\" ";
                });
            }
        }
Exemple #2
0
        private static void ConfigureLogging(ILoggingBuilder loggingBuilder, HostingOptions hostingOptions)
        {
            if (loggingBuilder == null)
            {
                throw new ArgumentNullException(nameof(loggingBuilder));
            }

            if (hostingOptions == null)
            {
                throw new ArgumentNullException(nameof(hostingOptions));
            }

            loggingBuilder.AddFilter((category, level) => level >= LogLevel.Warning || level == LogLevel.Trace);
            var hasJournalD = Tmds.Systemd.Journal.IsSupported;

            if (hasJournalD)
            {
                loggingBuilder.AddJournal(options =>
                {
                    options.SyslogIdentifier = "gridfs-server";
                    options.DropWhenBusy     = true;
                });
            }

            if (!hasJournalD || hostingOptions.ForceConsoleLogging)
            {
                loggingBuilder.AddConsole(options => options.DisableColors = true);
            }
        }
Exemple #3
0
 private static void ConfigureLogging(HostBuilderContext HostBuilderContext, ILoggingBuilder Logging)
 {
     if (Options.Mode == Mode.Daemon)
     {
         Logging.AddJournal(JournalOptions =>
         {
             JournalOptions.DropWhenBusy     = true;
             JournalOptions.SyslogIdentifier = "SecureDNS";
         });
     }
 }
        /// <summary>
        /// Adds a journal logger named 'SystemdJournal' to the factory.
        /// </summary>
        /// <param name="builder">The <see cref="ILoggingBuilder"/> to use.</param>
        /// <param name="configure"></param>
        public static ILoggingBuilder AddJournal(this ILoggingBuilder builder, Action <JournalLoggerOptions> configure)
        {
            if (configure == null)
            {
                throw new ArgumentNullException(nameof(configure));
            }

            builder.AddJournal();
            builder.Services.Configure(configure);

            return(builder);
        }