init: 初始框架
This commit is contained in:
36
Program.cs
Normal file
36
Program.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
using cloudPrintWinAgent;
|
||||
|
||||
var builder = Host.CreateApplicationBuilder(args);
|
||||
|
||||
|
||||
builder.Services.AddWindowsService(options =>
|
||||
{
|
||||
options.ServiceName = "CloudPrint WinAgent";
|
||||
});
|
||||
|
||||
builder.Services.AddHostedService<Worker>();
|
||||
|
||||
builder.Logging.ClearProviders();
|
||||
|
||||
if (Environment.UserInteractive)
|
||||
{
|
||||
// 交互式运行
|
||||
builder.Logging.AddConsole();
|
||||
}
|
||||
else
|
||||
{
|
||||
// 作为 Windows 服务运行
|
||||
builder.Logging.AddEventLog(eventLogSettings =>
|
||||
{
|
||||
eventLogSettings.SourceName = "CloudPrint WinAgent";
|
||||
eventLogSettings.LogName = "CloudPrint";
|
||||
});
|
||||
}
|
||||
|
||||
var host = builder.Build();
|
||||
await host.RunAsync();
|
||||
|
||||
Reference in New Issue
Block a user