using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Console; namespace Magic.Core; /// /// 日志写入文件扩展 /// public static class LoggingFileExtensions { /// /// 添加workerservice项目控制台日志格式化扩展 /// /// /// public static IHostBuilder UseLoggingFile(this IHostBuilder builder) { builder.ConfigureLogging(logging => { logging.ClearProviders(); logging.AddConsole(options => { options.FormatterName = "custom_format"; }).AddConsoleFormatter(); }); builder.ConfigureServices((hostContext, services) => { services.AddComponent(); }); return builder; } /// /// 添加api项目控制台日志格式化扩展 /// /// /// public static WebApplicationBuilder UseLoggingFile(this WebApplicationBuilder builder) { builder.Logging.ClearProviders(); builder.Logging.AddConsole(options => { options.FormatterName = "custom_format"; }).AddConsoleFormatter(); builder.Services.AddComponent(); return builder; } }