diff --git a/CrystalConnector/CrystalConnector.csproj b/CrystalConnector/CrystalConnector.csproj index 8b92b45..09b702b 100644 --- a/CrystalConnector/CrystalConnector.csproj +++ b/CrystalConnector/CrystalConnector.csproj @@ -8,7 +8,26 @@ - + + + + + + + + + + + + + PreserveNewest + + + PreserveNewest + + + + diff --git a/CrystalConnector/CrystalService.cs b/CrystalConnector/CrystalService.cs new file mode 100644 index 0000000..edeb159 --- /dev/null +++ b/CrystalConnector/CrystalService.cs @@ -0,0 +1,48 @@ +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using NLog; + +namespace CrystalConnector; + +public class CrystalService : IHostedService +{ + private ILogger Logger { get; } + private IConfiguration Config { get; } + + public CrystalService(ILogger logger, IConfiguration config, IHostApplicationLifetime appLifetime) + { + Logger = logger; + Config = config; + + appLifetime.ApplicationStarted.Register(OnStarted); + appLifetime.ApplicationStopping.Register(OnStopping); + appLifetime.ApplicationStopped.Register(OnStopped); + } + + private void OnStarted() + { + Logger.LogInformation("Starting!"); + } + + private void OnStopping() + { + Logger.LogInformation("Stopping!"); + } + + private void OnStopped() + { + } + + public Task StartAsync(CancellationToken cancellationToken) + { + return Task.CompletedTask; + } + + public Task StopAsync(CancellationToken cancellationToken) + { + LogManager.Shutdown(); + + return Task.CompletedTask; + } +} \ No newline at end of file diff --git a/CrystalConnector/NLog.config b/CrystalConnector/NLog.config new file mode 100644 index 0000000..b5594d1 --- /dev/null +++ b/CrystalConnector/NLog.config @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/CrystalConnector/Program.cs b/CrystalConnector/Program.cs index bac24da..b16dc49 100644 --- a/CrystalConnector/Program.cs +++ b/CrystalConnector/Program.cs @@ -1 +1,27 @@ -Console.WriteLine("Hello, world!"); +using CrystalConnector; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; +using LogLevel = Microsoft.Extensions.Logging.LogLevel; + +var builder = Host.CreateApplicationBuilder(args); + +builder.Services.AddHostedService(); + +// builder.Services.AddSingleton(); + +builder.Environment.ContentRootPath = Directory.GetCurrentDirectory(); +builder.Configuration.AddJsonFile("config.json", true) + .AddJsonFile($"config.{builder.Environment.EnvironmentName}.json") + .AddEnvironmentVariables(prefix: "CRYSTAL_") + .AddCommandLine(args); + +builder.Logging.ClearProviders() + .SetMinimumLevel(LogLevel.Trace) + .AddNLog(); + +using var host = builder.Build(); + +await host.RunAsync(); diff --git a/CrystalConnector/config.json b/CrystalConnector/config.json new file mode 100644 index 0000000..7a73a41 --- /dev/null +++ b/CrystalConnector/config.json @@ -0,0 +1,2 @@ +{ +} \ No newline at end of file