### Configure ServiceSelf in WebApplication Source: https://github.com/xljiulang/serviceself/blob/master/README.md Basic integration for a WebApplication by calling UseServiceSelf before and during host configuration. ```csharp static void Main(string[] args) { // 创建Host之前调用Service.UseServiceSelf(args) if (Service.UseServiceSelf(args)) { var builder = WebApplication.CreateBuilder(args); // 为Host配置UseServiceSelf() builder.Host.UseServiceSelf(); var app = builder.Build(); app.MapGet("/", context => context.Response.WriteAsync("ServiceSelf")); app.Run(); } } ``` -------------------------------- ### Configure ServiceSelf with Custom Options Source: https://github.com/xljiulang/serviceself/blob/master/README.md Advanced integration using ServiceOptions to define platform-specific service settings for Windows and Linux. ```csharp static void Main(string[] args) { var serviceName = "app"; var serviceOptions = new ServiceOptions { Arguments = new[] { new Argument("key", "value") }, Description = "这是演示示例应用", }; serviceOptions.Linux.Service.Restart = "always"; serviceOptions.Linux.Service.RestartSec = "10"; serviceOptions.Windows.DisplayName = "演示示例"; serviceOptions.Windows.FailureActionType = WindowsServiceActionType.Restart; if (Service.UseServiceSelf(args, serviceName, serviceOptions)) { var host = Host.CreateDefaultBuilder(args) // 为Host配置UseServiceSelf() .UseServiceSelf() .ConfigureServices(service => { service.AddHostedService(); }) .Build(); host.Run(); } } ``` -------------------------------- ### Control Service on Linux Source: https://github.com/xljiulang/serviceself/blob/master/README.md Commands to manage the service lifecycle and view logs on Linux platforms using sudo. ```bash sudo ./yourapp start // 安装并启动服务 ``` ```bash sudo ./yourapp stop // 停止并删除服务 ``` ```bash sudo ./yourapp logs // 控制台输出服务的日志 sudo ./yourapp logs filter="key words" // 控制台输出服务的日志 ``` -------------------------------- ### Control Service on Windows Source: https://github.com/xljiulang/serviceself/blob/master/README.md Commands to manage the service lifecycle and view logs on Windows platforms. ```bat yourapp.exe start // 安装并启动服务 ``` ```bat yourapp.exe stop // 停止并删除服务 ``` ```bat yourapp.exe logs // 控制台输出服务的日志 yourapp.exe logs filter="key words" // 控制台输出服务的日志 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.