Skip to content

Commit

Permalink
(#471) Fix logging
Browse files Browse the repository at this point in the history
  • Loading branch information
jibedoubleve committed Jan 17, 2024
1 parent 521b0c0 commit ad0f0bd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/Lanceur.Infra/Managers/ExecutionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Diagnostics;
using Lanceur.Core.BusinessLogic;
using Lanceur.Infra.LuaScripting;
using Lanceur.Infra.Utils;

namespace Lanceur.Infra.Managers
{
Expand Down Expand Up @@ -97,17 +98,18 @@ private IEnumerable<QueryResult> 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<QueryResult> ExecuteUwp(AliasQueryResult query)
Expand Down
25 changes: 25 additions & 0 deletions src/Lanceur.Infra/Utils/LoggerMixins.cs
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit ad0f0bd

Please sign in to comment.