-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
58 lines (48 loc) · 1.54 KB
/
Program.cs
File metadata and controls
58 lines (48 loc) · 1.54 KB
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
using Serilog;
using Serilog.Events;
using Serilog.Sinks.AzureAnalytics;
using System.Reflection;
// Start our smart AppHost
AppHost.Start(args, Assembly.GetEntryAssembly()?.GetName().Name);
// Create a Serilog Logger
Log.Logger = AppHost.CreateSerilogLogger(
(logger, configuration, env) =>
{
if (!string.IsNullOrEmpty(configuration["AzureLogAnalytics:WorkspaceId"])
&& !string.IsNullOrEmpty(configuration["AzureLogAnalytics:AuthenticationId"]))
{
logger.WriteTo.AzureAnalytics(
configuration["AzureLogAnalytics:WorkspaceId"],
configuration["AzureLogAnalytics:AuthenticationId"],
new ConfigurationSettings
{
Flatten = false,
LogName = $"{env.ApplicationName}{env.EnvironmentName}",
BufferSize = 1,
BatchSize = 1
},
restrictedToMinimumLevel: LogEventLevel.Information);
}
});
try
{
Log.Information("Starting AppHost");
using var host = AppHost
.CreateHostBuilder()
.ConfigureServices(ConsoleServiceCollectionExtensions.ConfigureServices)
.Build();
await host.StartAsync();
var result = await host.ExecuteAsync(async m => await m.RunAsync());
await host.StopAsync();
Log.Information("AppHost Stopped");
return result;
}
catch (Exception ex)
{
Log.Fatal(ex, "AppHost terminated unexpectedly");
return 1;
}
finally
{
Log.CloseAndFlush();
}