void UniversalService.ICommonService.OnStop() { StaticTestLogger.AppendLine("XXXService: StopAsync"); System.Console.WriteLine("XXXService: StopAsync"); this.Logger.LogInformation("CommonSampleService OnStop"); this.m_run = false; }
} // End Task RunDbSync void UniversalService.ICommonService.OnStart() { StaticTestLogger.AppendLine("XXXService: StartAsync"); System.Console.WriteLine("XXXService: StartAsync"); this.Logger.LogInformation("CommonSampleService OnStart"); this.m_run = true; System.Threading.Tasks.Task t = RunDbSync(); }
public async System.Threading.Tasks.Task RunDbSync() { while (this.m_run) { StaticTestLogger.AppendLine("XXXService: Tick"); System.Console.WriteLine("XXXService: Tick"); await System.Threading.Tasks.Task.Delay(1000); } // Whend } // End Task RunDbSync
} // End Task Main static async System.Threading.Tasks.Task RunService(string[] args) { StaticTestLogger.ResetLogfile(); var shb = new UniversalService.ServiceHostBuilder() .ConfigureHostConfiguration(configHost => { string dir = System.IO.Path.GetDirectoryName(typeof(Program).Assembly.Location); // dir = System.IO.Directory.GetCurrentDirectory(); configHost.SetBasePath(dir); configHost.AddCommandLine(args); configHost.AddEnvironmentVariables(prefix: "ASPNETCORE_"); }) .ConfigureAppConfiguration((hostContext, configApp) => { string dir = System.IO.Path.GetDirectoryName(typeof(Program).Assembly.Location); // dir = System.IO.Directory.GetCurrentDirectory(); configApp.SetBasePath(dir); configApp.AddCommandLine(args); configApp.AddEnvironmentVariables(prefix: "ASPNETCORE_"); configApp.AddJsonFile($"appsettings.json", true); configApp.AddJsonFile($"appsettings.{hostContext.HostingEnvironment.EnvironmentName}.json", true); // configApp.AddIniFile(""); }) .ConfigureLogging((hostContext, configLogging) => { configLogging.SetMinimumLevel(LogLevel.Information); configLogging.AddFilter(x => x >= LogLevel.Trace); configLogging.AddConsole(); configLogging.AddDebug(); // configLogging.AddSerilog(new LoggerConfiguration() // .ReadFrom.Configuration(hostContext.Configuration) // .CreateLogger()); }).UseStartUp <ServiceStartup>() .Build(); ; try { await shb.StartAsync(new System.Threading.CancellationToken()); } catch (System.Exception ex) { System.Console.WriteLine(ex.Message); System.Console.WriteLine(ex.StackTrace); } } // End Task RunService