Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 33 additions & 3 deletions src/Bootstrap/src/AutoConfiguration/BootstrapScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Steeltoe.Common;
using Steeltoe.Common.DynamicTypeAccess;
Expand Down Expand Up @@ -44,6 +45,7 @@ internal sealed partial class BootstrapScanner
private readonly AssemblyLoader _loader;
private readonly ILoggerFactory _loggerFactory;
private readonly ILogger _logger;
private bool _isSerilogLoaded;

public BootstrapScanner(HostBuilderWrapper wrapper, IReadOnlySet<string> assemblyNamesToExclude, ILoggerFactory loggerFactory)
{
Expand Down Expand Up @@ -76,7 +78,9 @@ public void ConfigureSteeltoe()
WireIfLoaded(WirePlaceholderResolver, SteeltoeAssemblyNames.ConfigurationPlaceholder);
WireIfLoaded(WireConnectors, SteeltoeAssemblyNames.Connectors);

if (!WireIfLoaded(WireDynamicSerilog, SteeltoeAssemblyNames.LoggingDynamicSerilog))
_isSerilogLoaded = WireIfLoaded(WireDynamicSerilog, SteeltoeAssemblyNames.LoggingDynamicSerilog);

if (!_isSerilogLoaded)
{
WireIfLoaded(WireDynamicConsole, SteeltoeAssemblyNames.LoggingDynamicConsole);
}
Expand Down Expand Up @@ -244,7 +248,20 @@ private void WireDiscoveryEureka()

private void WireAllActuators()
{
_wrapper.ConfigureServices(services => services.AddAllActuators());
if (_isSerilogLoaded)
{
_wrapper.ConfigureServices(services =>
{
#pragma warning disable S4792 // Configuring loggers is security-sensitive
services.AddLogging(loggingBuilder => loggingBuilder.AddDynamicSerilog());
#pragma warning restore S4792 // Configuring loggers is security-sensitive
services.AddAllActuators();
});
}
else
{
_wrapper.ConfigureServices(services => services.AddAllActuators());
}

LogActuatorsConfigured();
}
Expand All @@ -258,7 +275,20 @@ private void WirePrometheus()

private void WireDistributedTracingLogProcessor()
{
_wrapper.ConfigureServices(services => services.AddTracingLogProcessor());
if (_isSerilogLoaded)
{
_wrapper.ConfigureServices(services =>
{
#pragma warning disable S4792 // Configuring loggers is security-sensitive
services.AddLogging(loggingBuilder => loggingBuilder.AddDynamicSerilog());
#pragma warning restore S4792 // Configuring loggers is security-sensitive
services.AddTracingLogProcessor();
});
}
else
{
_wrapper.ConfigureServices(services => services.AddTracingLogProcessor());
}

LogDistributedTracingConfigured();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,25 @@ public async Task DynamicSerilog_IsAutowired(HostBuilderType hostBuilderType)
AssertDynamicSerilogIsAutowired(hostWrapper);
}

[Theory]
[InlineData(HostBuilderType.Host)]
[InlineData(HostBuilderType.WebHost)]
[InlineData(HostBuilderType.WebApplication)]
[InlineData(HostBuilderType.HostApplication)]
public async Task DynamicSerilog_WinsOverActuatorFallback(HostBuilderType hostBuilderType)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test doesn't seem to cover the reported problem. It succeeds even without the code changes.

{
var assembliesToInclude = new HashSet<string>
{
SteeltoeAssemblyNames.LoggingDynamicSerilog,
SteeltoeAssemblyNames.ManagementEndpoint
};

await using HostWrapper hostWrapper =
HostWrapperFactory.GetExcluding(SteeltoeAssemblyNames.All.Except(assembliesToInclude).ToHashSet(), hostBuilderType);

AssertDynamicSerilogIsAutowired(hostWrapper);
}

[Theory]
[InlineData(HostBuilderType.Host)]
[InlineData(HostBuilderType.WebHost)]
Expand Down
Loading