diff --git a/src/GaugeProjectBuilder.cs b/src/GaugeProjectBuilder.cs index a4f9d0d..027a35c 100644 --- a/src/GaugeProjectBuilder.cs +++ b/src/GaugeProjectBuilder.cs @@ -15,12 +15,10 @@ namespace Gauge.Dotnet; public class GaugeProjectBuilder : IGaugeProjectBuilder { private readonly IConfiguration _config; - private readonly ILogger _logger; - public GaugeProjectBuilder(IConfiguration config, ILogger logger) + public GaugeProjectBuilder(IConfiguration config) { _config = config; - _logger = logger; } public bool BuildTargetGaugeProject() @@ -65,14 +63,20 @@ public bool BuildTargetGaugeProject() } catch (NotAValidGaugeProjectException) { - _logger.LogCritical("Cannot locate a Project File in {ProjectRoot}", _config.GetGaugeProjectRoot()); + // Logger not available yet, so output log to console. + Console.WriteLine($$""" + { "logLevel": "fatal", "message": "Cannot locate a Project File in {{_config.GetGaugeProjectRoot()}}"} + """); throw; } catch (Exception ex) { if (!_config.IgnoreBuildFailures()) { - _logger.LogCritical("Unable to build Project in {ProjectRoot}\n{Message}\n{StackTrace}", _config.GetGaugeProjectRoot(), ex.Message, ex.StackTrace); + // Logger not available yet, so output log to console. + Console.WriteLine($$""" + { "logLevel": "fatal", "message": "Unable to build Project in {{_config.GetGaugeProjectRoot()}}\n{{ex.Message}}\n{{ex.StackTrace}}"} + """); throw; } return false; @@ -88,8 +92,6 @@ private int RunDotnetCommand(string args) Arguments = args }; var buildProcess = new Process { EnableRaisingEvents = true, StartInfo = startInfo }; - buildProcess.OutputDataReceived += (sender, e) => { _logger.LogDebug(e.Data); }; - buildProcess.ErrorDataReceived += (sender, e) => { _logger.LogError(e.Data); }; buildProcess.Start(); buildProcess.WaitForExit(); return buildProcess.ExitCode; diff --git a/src/Program.cs b/src/Program.cs index 9cb52a2..3d53310 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -42,6 +42,10 @@ private static async Task Main(string[] args) var builder = WebApplication.CreateBuilder(args); builder.Configuration.SetupConfiguration(); builder.Logging.SetupLogging(); + + Environment.CurrentDirectory = builder.Configuration.GetGaugeProjectRoot(); + var buildSucceeded = new GaugeProjectBuilder(builder.Configuration).BuildTargetGaugeProject(); + builder.WebHost.ConfigureKestrel(opts => { opts.Listen(IPAddress.Parse("127.0.0.1"), 0, (opt) => { opt.Protocols = HttpProtocols.Http2; }); @@ -50,8 +54,6 @@ private static async Task Main(string[] args) var app = builder.Build(); _logger = app.Services.GetRequiredService().CreateLogger("Gauge"); - Environment.CurrentDirectory = app.Configuration.GetGaugeProjectRoot(); - var buildSucceeded = app.Services.GetRequiredService().BuildTargetGaugeProject(); if (!buildSucceeded && !app.Configuration.IgnoreBuildFailures()) { return; @@ -113,7 +115,6 @@ private static IServiceCollection ConfigureServices(this IServiceCollection serv { services.AddGrpc(); services.AddSingleton(new PhysicalFileProvider(config.GetGaugeBinDir())); - services.AddTransient(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton();