-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
63 lines (56 loc) · 2.41 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
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using NLog;
using NLog.Config;
using NLog.Targets;
using NLog.Extensions.Logging;
using Mercurius.DBus;
using Mercurius.Configuration;
namespace Mercurius {
public class Program {
public static async Task Main(string[] args) {
ColoredConsoleTarget target = new ColoredConsoleTarget();
target.Layout = "[${date:format=HH\\:MM\\:ss}] ${logger} -> ${message}";
target.WordHighlightingRules.Add(
new ConsoleWordHighlightingRule("log",
ConsoleOutputColor.Cyan,
ConsoleOutputColor.NoChange));
target.WordHighlightingRules.Add(
new ConsoleWordHighlightingRule("warn",
ConsoleOutputColor.DarkYellow,
ConsoleOutputColor.NoChange));
target.WordHighlightingRules.Add(
new ConsoleWordHighlightingRule("fatal",
ConsoleOutputColor.Red,
ConsoleOutputColor.Black));
FileTarget logFile = new FileTarget();
logFile.Layout = "[${date:format=HH\\:MM\\:ss}] ${logger} -> ${message}";
logFile.CleanupFileName = true;
logFile.ArchiveFileName = "./latest.log";
logFile.ArchiveFileKind = FilePathKind.Relative;
NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(target, LogLevel.Trace);
// NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(logFile, LogLevel.Trace);
var builder = new HostBuilder()
.ConfigureAppConfiguration((hostingContext, config) => {
config.AddEnvironmentVariables();
if (args != null)
{
config.AddCommandLine(args);
}
})
.ConfigureServices((hostContext, services) => {
services.AddSingleton<IHostedService, DaemonService>();
})
.ConfigureServices((hostContext, services) => {
services.AddSingleton<IHostedService, DbusHandler>();
})
.ConfigureLogging((hostingContext, logging) => {
logging.AddNLog(hostingContext.Configuration);
});
await builder.RunConsoleAsync();
}
}
}