Virtuesoft.Framework.WindowsService
1.1.0
See the version list below for details.
dotnet add package Virtuesoft.Framework.WindowsService --version 1.1.0
NuGet\Install-Package Virtuesoft.Framework.WindowsService -Version 1.1.0
<PackageReference Include="Virtuesoft.Framework.WindowsService" Version="1.1.0" />
paket add Virtuesoft.Framework.WindowsService --version 1.1.0
#r "nuget: Virtuesoft.Framework.WindowsService, 1.1.0"
// Install Virtuesoft.Framework.WindowsService as a Cake Addin #addin nuget:?package=Virtuesoft.Framework.WindowsService&version=1.1.0 // Install Virtuesoft.Framework.WindowsService as a Cake Tool #tool nuget:?package=Virtuesoft.Framework.WindowsService&version=1.1.0
新建控制台程序
class Program { static void Main(string[] args) { new WindowsServiceHostBuilder() //默认app.json 文件配置 .UseConfigure() //采用对象进行配置 文件配置和对象配置二选一 .UseConfigure(option ⇒ { //是否桌面交互 option.IsDesktop = true; option.ServiceName = "服务名称"; option.Display = "显示名称"; option.Description = "详细描述"; //启动方式 option.StartOption = StartOption.auto; }) //控制台日志 .UseConsoleLogging() //文件日志 .UseFileLogging() //使用IO注入使用服务 .UseSingleton<SampleService>() //.UseTransient<SampleService>() //注入服务 .UseWindowsService<log>() //注入服务 .UseWindowsService<logSmart>() .Build() .Run(args); } }
//创建服务和对象 public class SampleService { /// <summary> /// 使用 IConfiguration 需要使用文件配置 /// </summary> /// <param name="logger"></param> /// <param name="configuration"></param> public SampleService(ILogger<SampleService> logger, IConfiguration configuration) {
}
}
public class log : IWindowsService
{
ILogger<log> Looger { get; }
public log(ILogger<log> looger,IServiceProvider serviceProvider) => Looger = looger;
public string Name => "Testing.Log";
public string Display => "测试服务";
public Task<bool> PauseAsync(CancellationToken cancellationToken = default)
{
return Task.FromResult(true);
}
public Task<bool> StartAsync(CancellationToken cancellationToken = default)
{
//Looger.LogInformation(DateTime.Now.ToString("HH:mm:ss fff"));
_=Task.Run(async () => {
while (true)
{
await Task.Delay(1000);
var configuare= this.GetService<WindowsServiceConfigure>();
Looger.LogInformation($"{configuare.ServiceName}:=>{DateTime.Now.ToString("HH:mm:ss fff")}" );
}
});
return Task.FromResult(true);
}
public Task<bool> StopAsync(CancellationToken cancellationToken = default)
{
return Task.FromResult(true);
}
}
public class logSmart : IWindowsService
{
ILogger<logSmart> Looger { get; }
public logSmart(ILogger<logSmart> looger) => Looger = looger;
public string Name => "Testing.logSmart";
public string Display => "测试服务";
public Task<bool> PauseAsync(CancellationToken cancellationToken = default)
{
return Task.FromResult(true);
}
public Task<bool> StartAsync(CancellationToken cancellationToken = default)
{
Task.Run(async () => {
while (true)
{
await Task.Delay(2000);
Looger.LogInformation(DateTime.Now.ToString("HH:mm:ss fff"));
}
});
return Task.FromResult(true);
}
public Task<bool> StopAsync(CancellationToken cancellationToken = default)
{
return Task.FromResult(true);
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.1 is compatible. |
-
.NETCoreApp 3.1
- Microsoft.Extensions.Configuration.FileExtensions (>= 5.0.0)
- Microsoft.Extensions.Configuration.Json (>= 5.0.0)
- Microsoft.Extensions.DependencyInjection (>= 5.0.1)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 5.0.0)
- Microsoft.Extensions.Logging.Console (>= 5.0.0)
- System.ServiceProcess.ServiceController (>= 5.0.0)
- Virtuesoft.Framework.Logging.FileServer (>= 1.0.4)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Virtuesoft.Framework.WindowsService:
Package | Downloads |
---|---|
Virtuesoft.Framework.WindowsService.WindowsHost
windows服务框架 |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
6.0.3 | 949 | 8/8/2022 |
6.0.2 | 1,051 | 2/9/2022 |
6.0.1 | 981 | 2/8/2022 |
6.0.0 | 1,008 | 1/24/2022 |
1.1.6 | 859 | 9/13/2021 |
1.1.5 | 919 | 7/28/2021 |
1.1.4 | 868 | 7/28/2021 |
1.1.3 | 880 | 7/28/2021 |
1.1.2 | 877 | 7/28/2021 |
1.1.1 | 877 | 7/27/2021 |
1.1.0 | 864 | 7/27/2021 |
1.0.9 | 903 | 7/27/2021 |
1.0.8 | 869 | 7/27/2021 |
1.0.7 | 898 | 7/26/2021 |
1.0.6 | 863 | 7/26/2021 |
1.0.5 | 884 | 7/25/2021 |
1.0.4 | 922 | 7/25/2021 |
1.0.2 | 881 | 7/25/2021 |
1.0.1 | 918 | 5/8/2021 |
1.0.0 | 933 | 5/7/2021 |