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.
35 lines
1.0 KiB
35 lines
1.0 KiB
7 days ago
|
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);
|
||
|
});
|
||
|
|
||
|
return services;
|
||
|
}
|
||
|
}
|