using ClassNotify.Service.Ipc; using ClassNotify.Service.Services; using ClassNotify.Service.Workers; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Serilog; Log.Logger = new LoggerConfiguration() .MinimumLevel.Information() .WriteTo.File( path: Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "ClassNotify", "logs", "service-.log"), rollingInterval: RollingInterval.Day, retainedFileCountLimit: 14, outputTemplate: "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff}] [{Level:u3}] {Message:lj}{NewLine}{Exception}") .CreateLogger(); try { Log.Information("Starting ClassNotify.Service daemon..."); var builder = Host.CreateDefaultBuilder(args) .UseWindowsService(options => { options.ServiceName = "ClassNotifyService"; }) .UseSerilog() .ConfigureServices((hostContext, services) => { services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddHostedService(); services.AddHostedService(); }); var host = builder.Build(); await host.RunAsync(); } catch (Exception ex) { Log.Fatal(ex, "ClassNotify.Service terminated unexpectedly."); } finally { Log.CloseAndFlush(); }