11using System . ComponentModel ;
22using Bing . AspNetCore ;
33using Bing . Core . Modularity ;
4- using Bing . Logs . Exceptionless ;
4+ using Bing . Logging . Serilog ;
55using Bing . Logs . NLog ;
6+ using Exceptionless ;
67using Microsoft . Extensions . DependencyInjection ;
8+ using Serilog ;
9+ using serilog = Serilog ;
710
811namespace Bing . Admin . Modules
912{
@@ -24,19 +27,36 @@ public class LogModule : AspNetCoreBingModule
2427 /// 级别默认为0,表示无依赖,需要在同级别有依赖顺序的时候,再重写为>0的顺序值
2528 /// </summary>
2629 public override int Order => 0 ;
27-
30+
2831 /// <summary>
2932 /// 添加服务。将模块服务添加到依赖注入服务容器中
3033 /// </summary>
3134 /// <param name="services">服务集合</param>
3235 public override IServiceCollection AddServices ( IServiceCollection services )
3336 {
3437 //services.AddNLog();
35- services . AddExceptionless ( o =>
38+ // 同时输出2种方式的日志,可能存在重复 需要陆续兼容
39+ Logs . Exceptionless . Extensions . AddExceptionless ( services , o =>
3640 {
3741 o . ApiKey = "ez9jumyxVxjTxqSm0oUQhCML3OGCkDfMGyW1hfmn" ;
3842 o . ServerUrl = "http://10.186.132.40:5100" ;
3943 } ) ;
44+ //ExceptionlessClient.Default.Configuration.ApiKey= "ez9jumyxVxjTxqSm0oUQhCML3OGCkDfMGyW1hfmn";
45+ //ExceptionlessClient.Default.Configuration.ServerUrl = "http://10.186.132.40:5100";
46+ //ExceptionlessClient.Default.Startup();
47+ services . AddLogging ( loggingBuilder =>
48+ {
49+ var configuration = services . GetConfiguration ( ) ;
50+ serilog . Log . Logger = new serilog . LoggerConfiguration ( )
51+ . Enrich . FromLogContext ( )
52+ . Enrich . WithLogContext ( )
53+ . Enrich . WithLogLevel ( )
54+ . WriteTo . Exceptionless ( )
55+ . ReadFrom . Configuration ( configuration )
56+ . ConfigLogLevel ( configuration )
57+ . CreateLogger ( ) ;
58+ loggingBuilder . AddSerilog ( ) ;
59+ } ) ;
4060 return services ;
4161 }
4262 }
0 commit comments