This commit is contained in:
老九 2021-11-14 21:50:22 +08:00
parent 9cc7ed0071
commit a375894f76

View File

@ -55,6 +55,7 @@ namespace FastGithub
/// <param name="singleton"></param> /// <param name="singleton"></param>
public static void Run(this IHost host, bool singleton = true) public static void Run(this IHost host, bool singleton = true)
{ {
var logger = host.Services.GetRequiredService<ILoggerFactory>().CreateLogger(nameof(FastGithub));
if (TryGetCommand(out var cmd) && (OperatingSystem.IsWindows() || OperatingSystem.IsLinux())) if (TryGetCommand(out var cmd) && (OperatingSystem.IsWindows() || OperatingSystem.IsLinux()))
{ {
try try
@ -67,11 +68,11 @@ namespace FastGithub
{ {
UseCommandAtLinux(cmd); UseCommandAtLinux(cmd);
} }
logger.LogInformation("服务操作成功");
} }
catch (Exception ex) catch (Exception ex)
{ {
var loggerFactory = host.Services.GetRequiredService<ILoggerFactory>(); logger.LogError(ex.Message);
loggerFactory.CreateLogger(nameof(FastGithub)).LogError(ex.Message);
} }
} }
else else
@ -81,6 +82,10 @@ namespace FastGithub
{ {
HostingAbstractionsHostExtensions.Run(host); HostingAbstractionsHostExtensions.Run(host);
} }
else
{
logger.LogWarning($"程序将自动关闭:系统已运行其它实例");
}
} }
} }