Skip to content

Commit

Permalink
Log trace logs to build output if not on TeamCity
Browse files Browse the repository at this point in the history
  • Loading branch information
acodrington committed Nov 9, 2023
1 parent 5911c70 commit 1649bd5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class LatestClientAndLatestServiceBuilder : IClientAndServiceBuilder
Reference<PortForwarder>? portForwarderReference;
Func<RetryPolicy>? pollingReconnectRetryPolicy;
ProxyFactory? proxyFactory;
LogLevel halibutLogLevel = LogLevel.Trace;
LogLevel halibutLogLevel = LogLevel.Info;
ConcurrentDictionary<string, ILog>? clientInMemoryLoggers;
ConcurrentDictionary<string, ILog>? serviceInMemoryLoggers;
ITrustProvider clientTrustProvider;
Expand Down
8 changes: 7 additions & 1 deletion source/Halibut.Tests/Support/SerilogLoggerBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static SerilogLoggerBuilder()

Logger = new LoggerConfiguration()
.MinimumLevel.Verbose()
.WriteTo.Sink(new NonProgressNUnitSink(new MessageTemplateTextFormatter(nUnitOutputTemplate)), LogEventLevel.Debug)
.WriteTo.Sink(new NonProgressNUnitSink(new MessageTemplateTextFormatter(nUnitOutputTemplate)))
.WriteTo.Sink(new TraceLogsForFailedTestsSink(new MessageTemplateTextFormatter(localOutputTemplate)))
.CreateLogger();
}
Expand Down Expand Up @@ -98,6 +98,12 @@ public void Emit(LogEvent logEvent)
throw new ArgumentNullException(nameof(logEvent));
if (TestContext.Out == null)
return;

// SerilogLoggerBuilder creates this sink with Verbose logging, but we only want Verbose logging
// if we're running locally, as Verbose logs spam the TeamCity build log.
if (TeamCityDetection.IsRunningInTeamCity() && logEvent.Level < LogEventLevel.Debug)
return;

var output = new StringWriter();
if (logEvent.Properties.TryGetValue("SourceContext", out var sourceContext))
{
Expand Down

0 comments on commit 1649bd5

Please sign in to comment.