diff --git a/src/Lanceur.Infra/Managers/ExecutionManager.cs b/src/Lanceur.Infra/Managers/ExecutionManager.cs index 0794d379..6ab73cde 100644 --- a/src/Lanceur.Infra/Managers/ExecutionManager.cs +++ b/src/Lanceur.Infra/Managers/ExecutionManager.cs @@ -9,6 +9,7 @@ using System.Diagnostics; using Lanceur.Core.BusinessLogic; using Lanceur.Infra.LuaScripting; +using Lanceur.Infra.Utils; namespace Lanceur.Infra.Managers { @@ -97,17 +98,18 @@ private IEnumerable ExecuteProcess(AliasQueryResult query) WorkingDirectory = query.WorkingDirectory, WindowStyle = query.StartMode.AsWindowsStyle(), }; - + using var __ = _logger.ScopeProcessStartInfo(psi); if (query.IsElevated || query.RunAs == SharedKernel.Constants.RunAs.Admin) { psi.Verb = "runas"; _logger.LogInformation("Run {FileName} as ADMIN", query.FileName); } - - _logger.BeginSingleScope("ProcessStartInfo", psi); - _logger.LogDebug("Executing process for alias {AliasName}", query.Name); - using var __ = Process.Start(psi); - return QueryResult.NoResult; + + using (Process.Start(psi)) + { + _logger.LogDebug("Executing process for alias {AliasName}", query.Name); + return QueryResult.NoResult; + } } private IEnumerable ExecuteUwp(AliasQueryResult query) diff --git a/src/Lanceur.Infra/Utils/LoggerMixins.cs b/src/Lanceur.Infra/Utils/LoggerMixins.cs new file mode 100644 index 00000000..497bf4c8 --- /dev/null +++ b/src/Lanceur.Infra/Utils/LoggerMixins.cs @@ -0,0 +1,25 @@ +using Lanceur.Infra.Logging; +using Microsoft.Extensions.Logging; +using System.Diagnostics; + +namespace Lanceur.Infra.Utils; + +public static class LoggerMixins +{ + #region Methods + + public static IDisposable ScopeProcessStartInfo(this ILogger logger, ProcessStartInfo psi) + { + return logger.BeginSingleScope("ProcessStartInfo", new + { + psi.FileName, + psi.Verb, + psi.Arguments, + psi.UseShellExecute, + psi.WorkingDirectory, + psi.WindowStyle + }); + } + + #endregion Methods +} \ No newline at end of file