From 9f78185e15b2f7ae482642ecf4b463dc2da41f12 Mon Sep 17 00:00:00 2001 From: Timothy Schenk Date: Sat, 31 Dec 2022 14:31:42 +0100 Subject: [PATCH] Setup DI and Logging --- Server/Program.cs | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/Server/Program.cs b/Server/Program.cs index e5dff12..9316528 100644 --- a/Server/Program.cs +++ b/Server/Program.cs @@ -1,3 +1,25 @@ -// See https://aka.ms/new-console-template for more information +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; +using ReInject; -Console.WriteLine("Hello, World!"); \ No newline at end of file +var services = Injector.GetContainer(); + +var configuration = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build(); + +services.Register(DependencyStrategy.AtomicInstance, true, configuration); + +ILoggerFactory loggerFactory = LoggerFactory.Create(builder => +{ + builder.AddSimpleConsole(options => + { + options.ColorBehavior = Microsoft.Extensions.Logging.Console.LoggerColorBehavior.Enabled; + options.TimestampFormat = "[HH:mm:ss]"; + }); + builder.AddFile("Logs/log-{0:yyyy}-{0:MM}-{0:dd}.txt", + opts => opts.FormatLogFileName = fileName => String.Format(fileName, DateTime.UtcNow)); +}); + +services.Register(DependencyStrategy.AtomicInstance, true, loggerFactory); + +var authServer = services.GetInstance(); +authServer.Start(); \ No newline at end of file