37 lines
754 B
C#
37 lines
754 B
C#
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();
|
|
|