Blame view

泰额版/Food Labeling Management Code/Yi.Abp.Net8/src/Yi.Abp.Web/Program.cs 2.53 KB
59e51671   “wangming”   1
1
2
3
4
5
6
  using Serilog;
  using Serilog.Events;
  using Yi.Abp.Web;
  
  //创建日志,可使用{SourceContext}记录
  Log.Logger = new LoggerConfiguration()
a1a0369d   李曜臣   5-25代码优化
7
8
      .Filter.ByExcluding(log => log.Exception?.GetType() == typeof(TaskCanceledException)
          || log.MessageTemplate.Text.Contains("\"message\": \"A task was canceled.\""))
59e51671   “wangming”   1
9
10
11
12
13
      .MinimumLevel.Debug()
      .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
      .MinimumLevel.Override("Microsoft.AspNetCore.Hosting.Diagnostics", LogEventLevel.Error)
      .MinimumLevel.Override("Quartz", LogEventLevel.Warning)
      .Enrich.FromLogContext()
a1a0369d   李曜臣   5-25代码优化
14
15
16
17
18
      .WriteTo.Async(c => c.File("logs/all/log-.txt", rollingInterval: RollingInterval.Day,
          restrictedToMinimumLevel: LogEventLevel.Debug))
      .WriteTo.Async(c => c.File("logs/error/errorlog-.txt", rollingInterval: RollingInterval.Day,
          restrictedToMinimumLevel: LogEventLevel.Error))
      .WriteTo.Console()
59e51671   “wangming”   1
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
      .CreateLogger();
  
  try
  {
      Log.Information("""
  
          __     ___   ______                                           _    
          \ \   / (_) |  ____|                                         | |   
           \ \_/ / _  | |__ _ __ __ _ _ __ ___   _____      _____  _ __| | __
            \   / | | |  __| '__/ _` | '_ ` _ \ / _ \ \ /\ / / _ \| '__| |/ /
             | |  | | | |  | | | (_| | | | | | |  __/\ V  V / (_) | |  |   < 
             |_|  |_| |_|  |_|  \__,_|_| |_| |_|\___| \_/\_/ \___/|_|  |_|\_\
     
       """);
      Log.Information("Yi框架-Abp.vNext,启动!");
  
a1a0369d   李曜臣   5-25代码优化
35
36
37
38
39
40
41
      // 与美国版相同:工作目录切到【本项目文件夹】,只读这一份 appsettings.json
      var projectDir = Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "..", "..", ".."));
      if (File.Exists(Path.Combine(projectDir, "appsettings.json")))
      {
          Directory.SetCurrentDirectory(projectDir);
      }
  
59e51671   “wangming”   1
42
      var builder = WebApplication.CreateBuilder(args);
a1a0369d   李曜臣   5-25代码优化
43
44
45
46
      Log.Information("当前主机启动环境-【{Environment}】", builder.Environment.EnvironmentName);
      Log.Information("当前工作目录-【{Cwd}】", Directory.GetCurrentDirectory());
      Log.Information("当前主机启动地址-【{SelfUrl}】", builder.Configuration["App:SelfUrl"]);
      builder.WebHost.UseUrls(builder.Configuration["App:SelfUrl"]!);
59e51671   “wangming”   1
47
48
49
50
51
52
53
54
55
56
57
58
59
60
      builder.Host.UseAutofac();
      builder.Host.UseSerilog();
      await builder.Services.AddApplicationAsync<YiAbpWebModule>();
      var app = builder.Build();
      await app.InitializeApplicationAsync();
      await app.RunAsync();
  }
  catch (Exception ex)
  {
      Log.Fatal(ex, "Yi框架-Abp.vNext,爆炸!");
  }
  finally
  {
      Log.CloseAndFlush();
a1a0369d   李曜臣   5-25代码优化
61
  }