-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathProgram.cs
More file actions
63 lines (51 loc) · 1.85 KB
/
Copy pathProgram.cs
File metadata and controls
63 lines (51 loc) · 1.85 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
59
60
61
62
63
using MergerLogic.Clients;
using MergerLogic.Extensions;
using MergerService.Src;
using MergerService.Utils;
using System.Reflection;
string reflectionLocation = Assembly.GetExecutingAssembly().Location;
string reflectionLocationDir = Path.GetDirectoryName(reflectionLocation);
var builder = WebApplication.CreateBuilder(new WebApplicationOptions
{
ContentRootPath = reflectionLocationDir,
WebRootPath = reflectionLocationDir,
Args = args
});
builder.Configuration.AddJsonFile("appsettings.json", optional: true, reloadOnChange: false);
Console.WriteLine($"ContentRoot Path: {builder.Environment.ContentRootPath}");
Console.WriteLine($"WebRootPath: {builder.Environment.WebRootPath}");
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.RegisterMergerLogicType();
builder.Services.AddSingleton<IRun, Run>();
builder.Services.AddSingleton<ITaskUtils, TaskUtils>();
builder.Services.AddSingleton<IHeartbeatClient, HeartbeatClient>();
var app = builder.Build();
app.MapControllers();
var logger = app.Services.GetRequiredService<ILogger<Program>>();
AppDomain.CurrentDomain.UnhandledException += OnUnhandledExceptionEventHandler;
new Thread(() =>
{
try
{
app.Run();
}
catch (Exception e)
{
logger.LogCritical(e, $"UnhandledExceptionEvent occured, Message: {e.Message}");
}
});
try
{
app.Services.GetRequiredService<IRun>().Start();
}
catch (Exception e)
{
logger.LogCritical(e, $"UnhandledExceptionEvent occured, Message: {e.Message}");
}
void OnUnhandledExceptionEventHandler(object sender, UnhandledExceptionEventArgs e)
{
logger.LogCritical(e.ExceptionObject as Exception, $"UnhandledExceptionEvent occured, IsTerminating: {e.IsTerminating}");
}