/// <summary> /// 日志配置 /// </summary> /// <param name="builder"></param> public static void LoggingConfig(ILoggingBuilder builder) { builder.Services.AddTransient(provider => ConfigurationHelper.Root); var config = ConfigurationHelper.Root.GetSection("Logging"); builder.AddConfiguration(config); if (config.GetValue("Console", true)) { builder.AddConsole(); } builder.AddConsole(); }
private static void SetupLogging(WebHostBuilderContext context, ILoggingBuilder builder) { builder.ClearProviders(); if (context.HostingEnvironment.IsDevelopment()) { builder.AddDebug().SetMinimumLevel(LogLevel.Trace); builder.AddConsole().SetMinimumLevel(LogLevel.Trace); } else { builder.AddConsole().SetMinimumLevel(LogLevel.Warning); } }
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); } }
public static ILoggingBuilder AddLogging(this ILoggingBuilder builder, PiraeusConfig config) { LoggerType loggerTypes = config.GetLoggerTypes(); //if (loggerTypes.HasFlag(LoggerType.None)) //{ // return builder; //} LogLevel logLevel = Enum.Parse <LogLevel>(config.LogLevel, true); if (loggerTypes.HasFlag(LoggerType.Console)) { builder.AddConsole(); } if (loggerTypes.HasFlag(LoggerType.Debug)) { builder.AddDebug(); } builder.SetMinimumLevel(logLevel); return(builder); }
public static ILoggingBuilder AddLoggingConfiguration(this ILoggingBuilder loggingBuilder, IConfiguration configuration) { var loggingOptions = new Options.LoggingOptions(); configuration.GetSection("Logging").Bind(loggingOptions); foreach (var provider in loggingOptions.Providers) { switch (provider.Name.ToLower()) { case "console": { loggingBuilder.AddConsole(); break; } // case "azureappservices": // { // AzureAppServiceDiagnosticExtension.AddAzureWebAppDiagnostics(configuration, loggingBuilder); // break; // } default: { break; } } } return(loggingBuilder); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggingBuilder loggerFactory) { loggerFactory.AddConsole(); loggerFactory.AddDebug(); // Enable Api Extensions app.UseApiExtensions(); app.UseMvc(); // Enable middleware to serve generated Swagger as a JSON endpoint app.UseSwagger(c => { c.RouteTemplate = "docs/{documentName}/swagger.json"; }); // Enable middleware to serve swagger-ui assets (HTML, JS, CSS etc.) app.UseSwaggerUI(options => { options.SwaggerEndpoint("/docs/v1/swagger.json", "V1 Documentation"); options.SwaggerEndpoint("/docs/v2/swagger.json", "V2 Documentation"); }); app.UseSwaggerUiRedirect(); }
public static ILoggingBuilder AddLoggingConfiguration(this ILoggingBuilder loggingBuilder, IConfiguration configuracion) { var loggingOpciones = new LoggingOpciones(); configuracion.GetSection("Logging").Bind(loggingOpciones); // TODO: Confusión. Agregar aquí un proveedor, porque no se en donde se agrega! ProveedorLoggingOpciones opciones = new ProveedorLoggingOpciones(); opciones.Nombre = "file"; opciones.LogLevel = 1; ProveedorLoggingOpciones[] proveedorOpciones = new ProveedorLoggingOpciones[] { opciones }; loggingOpciones.Proveedores = proveedorOpciones; foreach (var provider in loggingOpciones.Proveedores) { switch (provider.Nombre.ToLower()) { case "console": { loggingBuilder.AddConsole(); break; } case "file": { string rutaArchivo = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), "logs", $"tateti_{System.DateTime.Now.ToString("ddMMyyHHmm")}.log"); loggingBuilder.AddFile(rutaArchivo, (LogLevel)provider.LogLevel); break; } default: { break; } } } return(loggingBuilder); }
public static void ConfigureLogging(WebHostBuilderContext host, ILoggingBuilder builder) { builder.AddConfiguration(host.Configuration.GetSection("Logging")); builder.AddConsole(); builder.AddDebug(); builder.AddFilter(DbLoggerCategory.Database.Connection.Name, LogLevel.Information); }
public virtual void ConfigureLogging(IConfiguration configuration, ILoggingBuilder logging) { Configuration = configuration; logging.AddConfiguration(configuration.GetSection("Logging")); logging.AddConsole(); // TODO: logging }
/// <summary> /// Configures an <see cref="ILoggingBuilder"/> with the base logging providers. /// </summary> /// <param name="loggingBuilder">The logging builder to configure.</param> private static void ConfigureBaseLogging(ILoggingBuilder loggingBuilder) { loggingBuilder.ClearProviders(); loggingBuilder.AddConsole(); loggingBuilder.AddDebug(); loggingBuilder.AddEventSourceLogger(); }
public static void Handle(bool isProduction, ILoggingBuilder builder, string awsLogGroupName) { builder.ClearProviders(); if (!isProduction) { builder.AddConsole(); } if (string.IsNullOrEmpty(awsLogGroupName)) { return; } using var cloudwatchLogsClient = new AmazonCloudWatchLogsClient(); bool logGroupExists = LogGroupExists(cloudwatchLogsClient, awsLogGroupName); if (!logGroupExists) { int days = isProduction ? 30 : 1; CreateLogGroup(cloudwatchLogsClient, awsLogGroupName, days); } var awsLoggerConfig = new AWSLoggerConfig { LogGroup = awsLogGroupName, BatchPushInterval = isProduction ? TimeSpan.FromMinutes(1) : TimeSpan.FromSeconds(2), DisableLogGroupCreation = true, LogStreamNamePrefix = string.Empty }; builder.AddAWSProvider(awsLoggerConfig, LogLevel.Information); Console.WriteLine($"Will write logs to: {awsLogGroupName}"); }
static void ConfigureLogger(WebHostBuilderContext ctx, ILoggingBuilder logging) { // Setups up the logging configuration from the location of our json config information logging.AddConfiguration(ctx.Configuration.GetSection("Logging")); logging.AddConsole(); logging.AddDebug(); }
public static ILoggingBuilder AddLoggingConfiguration(this ILoggingBuilder loggingBuilder, IConfiguration configuration) { var loggingOptions = new Options.LoggingOptions(); configuration.GetSection("Logging").Bind(loggingOptions); foreach (var provider in loggingOptions.Providers) { switch (provider.Name.ToLower()) { case "console": { loggingBuilder.AddConsole(); break; } case "file": { string filePath = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), "logs", $"CarWashBooking_{System.DateTime.Now.ToString("ddMMyyHHmm")}.log"); loggingBuilder.AddFile(filePath, (LogLevel)provider.LogLevel); string filePathError = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), "logs", $"CarWashBooking_Error{System.DateTime.Now.ToString("ddMMyyHHmm")}.log"); loggingBuilder.AddFileError(filePathError); break; } default: { break; } } } return(loggingBuilder); }
private static void ConfigureLogging(HostBuilderContext hostingContext, ILoggingBuilder logging) { // logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging")); logging.AddConsole(); logging.AddDebug(); logging.AddEventSourceLogger(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline public void Configure(IApplicationBuilder app, IHostEnvironment env, ILoggingBuilder loggerFactory, ISeriLogger seriLogger, IHostApplicationLifetime appLifetime, EnvironmentConfig environmentConfig) { seriLogger.Configure(loggerFactory, Configuration, appLifetime, env, environmentConfig); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); loggerFactory.AddConfiguration(Configuration.GetSection("Logging")); loggerFactory.AddConsole(); loggerFactory.AddDebug(); } else { app.UseHsts(); } app.UseHttpsRedirection(); app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
private static void SetupTestLogging(ILoggingBuilder builder) { builder .AddConsole() .SetMinimumLevel(LogLevel.Debug) .AddFilter("OmniSharp", LogLevel.Warning); }
private void ConfigureLogging(HostBuilderContext context, ILoggingBuilder loggingBuilder) { var configuration = context.Configuration; var loggingSection = configuration.GetSection("Logging"); try { loggingBuilder.ClearProviders(); loggingBuilder.AddConsole(); loggingBuilder.AddDebug(); var logFile = loggingSection.GetSection("File:Path").Value; if (!string.IsNullOrWhiteSpace(logFile)) { var logFileExpanded = Environment.ExpandEnvironmentVariables(logFile); var directoryName = Path.GetDirectoryName(logFileExpanded); Directory.CreateDirectory(directoryName); loggingBuilder.AddFile(loggingSection); } } catch (Exception e) { Console.WriteLine($"Warning. Could not create logfile: Exception: {e}"); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggingBuilder loggerFactory) { loggerFactory.AddConsole(); loggerFactory.AddDebug(); if (env.EnvironmentName.Equals("Development")) { //var delay = new TimeSpan(0, 0, 0, 0, 300); //300 ms var delay = new TimeSpan(0, 0, 1); // 1s app.UseSimulatedLatency(delay, delay); app.UseDeveloperExceptionPage(); app.UseBrowserLink(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); }); }
public async Task Execute(ILoggingBuilder builder, LoggerItemConfiguration configuration) { //反序列化特定配置 var innerConfiguration = JsonSerializerHelper.Deserialize <ConsoleConfiguration>(JsonSerializerHelper.Serializer(configuration.ConfigurationObj)); //绑定提供方 builder.AddConsole((opt) => { if (innerConfiguration != null) { opt.DisableColors = innerConfiguration.DisableColors; opt.IncludeScopes = innerConfiguration.IncludeScopes; } }); //配置级别过滤 foreach (var filterItem in configuration.LogLevels) { builder.AddFilter <ConsoleLoggerProvider>(filterItem.Key, filterItem.Value); } //配置其他未指定目录的最低级别 builder.AddFilter <ConsoleLoggerProvider>((level) => { if (level < configuration.DefaultMinLevel) { return(false); } return(true); }); await Task.FromResult(0); }
public static ILoggingBuilder AddOtelJsonConsole(this ILoggingBuilder builder) { builder.AddConsoleFormatter <OtelJsonConsoleFormatter, OtelJsonConsoleFormatterOptions>(); builder.AddConsole(options => options.FormatterName = "oteljson"); return(builder); }
public static ILoggingBuilder AddLoggingConfiguration(this ILoggingBuilder loggingBuilder, IConfiguration configuration) { var loggingOptions = new Options.LoggingOptions(); configuration.GetSection("Logging").Bind(loggingOptions); foreach (var provider in loggingOptions.Providers) { switch (provider.Name.ToLower()) { case "console": { loggingBuilder.AddConsole(); break; } case "file": { var filePath = Path.Combine(Directory.GetCurrentDirectory(), "logs", $"TicTacToe_{DateTime.Now.ToString("ddMMyyHHmm")}.log"); loggingBuilder.AddFile(filePath, (LogLevel)provider.LogLevel); break; } } } return(loggingBuilder); }
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggingBuilder loggerFactory) { loggerFactory.AddNLog(); loggerFactory.AddConsole(); LogManager.LoadConfiguration("NLog.config"); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseIdentityServer(); app.UseHttpsRedirection(); app.UseRouting(); //app.UseMvc((routes => //{ //})); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
private void LoggerOpts(ILoggingBuilder builder) { if (Environment.IsDevelopment()) { builder.AddConsole(); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggingBuilder loggerFactory) { loggerFactory.AddConsole(); loggerFactory.AddDebug(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); //Add authorization middleware app.UseAuth(); app.UseSession(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); app.UseSwagger(); app.UseSwaggerUi(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline public void Configure(IApplicationBuilder app, ILoggingBuilder loggingBuilder) { loggingBuilder.AddConsole(); loggingBuilder.AddDebug(); app.UseMvc(); }
private static void AddConsoleLogger(this ILoggingBuilder loggingBuilder) { loggingBuilder.AddConsole(options => { options.DisableColors = false; options.TimestampFormat = "[HH:mm:ss:fff] "; }); }
/// <summary> /// Configure <paramref name="builder"/> with a ConsoleLoggerProvider and a TraceSourceLoggerProvider which logs to <paramref name="filePath"/> /// This is to restore legacy default behavior of LogManager, which configure LogManager with a FileTelemetryConsumer and ConsoleTelemetryConsumer /// by default; /// </summary> /// <param name="builder"></param> /// <param name="filePath"></param> public static void ConfigureDefaultLoggingBuilder(ILoggingBuilder builder, string filePath) { if (ConsoleText.IsConsoleAvailable) { builder.AddConsole(); } builder.AddFile(filePath); }
public static void ConfigureLogging(WebHostBuilderContext hostingContext, ILoggingBuilder logging) { logging.ClearProviders(); logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging")); logging.AddConsole(); logging.AddDebug(); logging.AddEventSourceLogger(); }
private static void LogConfig(ILoggingBuilder log) { log.AddConsole(); log.AddFilter("GetOnBoard", LogLevel.Information); log.AddFilter("Microsoft.AspNetCore.Mvc", LogLevel.Error); log.AddFilter("Microsoft.AspNetCore.Hosting", LogLevel.Error); log.AddFilter("Microsoft.AspNetCore.Routing", LogLevel.Error); }
private static void SetupLogging(HostBuilderContext context, ILoggingBuilder builder) { builder.ClearProviders(); builder.AddDebug().SetMinimumLevel(LogLevel.Debug); builder.AddConsole().SetMinimumLevel(LogLevel.Debug); }