forked from ctrager/budoco
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
97 lines (82 loc) · 3.45 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Serilog;
using Serilog.Events;
namespace budoco
{
public class Program
{
public static int Main(string[] args)
{
Console.WriteLine("Main"); // here on purpose
// We have to load_config first to get Serilog's folder
bd_config.load_config();
string log_file_location = bd_config.get(bd_config.LogFileFolder) + "/budoco_log_.txt";
LogEventLevel microsoft_level = (LogEventLevel)bd_config.get(bd_config.DebugLogLevelMicrosoft);
LogEventLevel budoco_lovel = (LogEventLevel)bd_config.get(bd_config.DebugLogLevelBudoco);
LogEventLevel postgres_level = (LogEventLevel)bd_config.get(bd_config.DebugLogLevelPostgres);
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Verbose()
.MinimumLevel.Override("Microsoft", microsoft_level)
.MinimumLevel.Override("bd", budoco_lovel)
.MinimumLevel.Override("bd_pg", postgres_level)
.Enrich.FromLogContext()
.WriteTo.Console(outputTemplate:
"{Timestamp:HH:mm:ss.ms} {Level:u3} {SourceContext} {Message:lj}{NewLine}{Exception}")
.WriteTo.File(log_file_location,
rollingInterval: RollingInterval.Day,
outputTemplate:
"{Timestamp:HH:mm:ss.ms} {Level:u3} {SourceContext} {Message:lj}{NewLine}{Exception}")
.CreateLogger();
// We have to do this after the Serilog setup.
bd_util.init_serilog_context();
// Write config to log, even though budoco can pick up most changes without
// being restarted and we don't log the changed values.
bd_config.log_config();
try
{
Log.Information("Starting host");
CreateHostBuilder(args).Build().Run();
return 0;
}
catch (Exception ex)
{
Log.Fatal(ex, "Host terminated unexpectedly");
return 1;
}
finally
{
Log.CloseAndFlush();
}
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.UseSerilog()
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
webBuilder.UseKestrel(options =>
{
// Because we will control it with nginx,
// which gives good specific 413 status rather than vague 400 status
options.Limits.MaxRequestBodySize = null;
// This works
//options.ListenAnyIP(8000);
});
});
// public static IHostBuilder CreateHostBuilder(string[] args) =>
// Host.CreateDefaultBuilder(args)
// // dotnet install package Serilog.AspNetCore
// .UseSerilog()
// .ConfigureWebHostDefaults(webBuilder =>
// {
// webBuilder.UseStartup<Startup>();
// });
}
}