Setup DI and Logging

This commit is contained in:
Timothy Schenk 2022-12-31 14:31:42 +01:00
parent 864ed2ceb1
commit 9f78185e15

View file

@ -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!");
var services = Injector.GetContainer();
var configuration = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build();
services.Register<IConfiguration>(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<ILoggerFactory>(DependencyStrategy.AtomicInstance, true, loggerFactory);
var authServer = services.GetInstance<Server.AuthorizationServer>();
authServer.Start();