You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.1 KiB
37 lines
1.1 KiB
using CoreAgent.Infrastructure.Logging;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Logging;
|
|
using Serilog;
|
|
using Serilog.Events;
|
|
|
|
namespace CoreAgent.Infrastructure.Extensions.Logging;
|
|
|
|
/// <summary>
|
|
/// 日志扩展方法
|
|
/// </summary>
|
|
public static class LoggingExtensions
|
|
{
|
|
/// <summary>
|
|
/// 添加日志服务
|
|
/// </summary>
|
|
/// <param name="services">服务集合</param>
|
|
/// <returns>服务集合</returns>
|
|
public static IServiceCollection AddLoggingService(this IServiceCollection services, IConfiguration configuration)
|
|
{
|
|
// 初始化应用程序日志记录器
|
|
ApplicationLogger.Initialize(configuration);
|
|
Log.Information("Application starting...");
|
|
|
|
// 添加 Serilog 到依赖注入容器
|
|
services.AddLogging(loggingBuilder =>
|
|
{
|
|
loggingBuilder.ClearProviders();
|
|
loggingBuilder.AddSerilog(dispose: true);
|
|
loggingBuilder.AddConsole();
|
|
loggingBuilder.SetMinimumLevel(LogLevel.Information);
|
|
});
|
|
|
|
return services;
|
|
}
|
|
}
|