Skip to content

Commit

Permalink
fix a typo, In Serilog setup, catch pre-existing IDynamicLoggerProvid…
Browse files Browse the repository at this point in the history
…er registration
  • Loading branch information
Tim Hess committed Nov 13, 2019
1 parent c971259 commit 8b58d90
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public static class SerilogBuilderExtensions
/// <returns>The configured <see cref="ILoggingBuilder"/></returns>
public static ILoggingBuilder AddSerilogDynamicConsole(this ILoggingBuilder builder)
{
if (builder.Services.Any(sd => sd.ServiceType == typeof(IDynamicLoggerProvider)))
{
throw new InvalidOperationException("An IDynamicLoggerProvider has already been configured! Call 'AddSerilogDynamicConsole' earlier in program.cs (Before AddCloudFoundryActuators()) or remove duplicate IDynamicLoggerProvider entries.");
}

builder.Services.AddSingleton<ISerilogOptions, SerilogOptions>();
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<ILoggerProvider, SerilogDynamicProvider>());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public override void ProcessEvent(string evnt, object arg)

HandleAfterActionEvent();

Logger?.LogTrace("HandleAfterActionEvent finsih {thread}", Thread.CurrentThread.ManagedThreadId);
Logger?.LogTrace("HandleAfterActionEvent finish {thread}", Thread.CurrentThread.ManagedThreadId);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,10 @@ public void AddCloudFoundryActuators_IHostBuilder_Serilog()
{
// Arrange
var hostBuilder = Host.CreateDefaultBuilder()
.AddCloudFoundryActuators()
.ConfigureLogging(logging => logging.AddSerilogDynamicConsole())
.ConfigureAppConfiguration(cbuilder => cbuilder.AddInMemoryCollection(managementSettings))
.ConfigureWebHost(configureApp => configureApp.UseTestServer());
.ConfigureWebHost(configureApp => configureApp.UseTestServer())
.AddCloudFoundryActuators();

// Act
var host = hostBuilder.Build();
Expand Down

0 comments on commit 8b58d90

Please sign in to comment.