Skip to content

Commit

Permalink
Fix modifying collection while enumerating (#2844)
Browse files Browse the repository at this point in the history
  • Loading branch information
jviau authored and fabiocav committed Nov 13, 2024
1 parent 9d2aa7d commit 34284c6
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions src/DotNetWorker/Builder/FunctionsApplicationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Azure.Functions.Worker.Middleware;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -41,21 +42,21 @@ internal FunctionsApplicationBuilder(string[]? args)
_bootstrapHostBuilder.Context.Properties[SkipDefaultWorkerMiddlewareKey] = true;

_bootstrapHostBuilder
.ConfigureDefaults(args)
.ConfigureServices(services =>
{
// The console logger can result in duplicate logging.
foreach (var descriptor in services)
{
if (descriptor.ServiceType == typeof(ILoggerProvider) &&
descriptor.ImplementationType == typeof(ConsoleLoggerProvider))
{
services.Remove(descriptor);
break;
}
}
})
.ConfigureFunctionsWorkerDefaults();
.ConfigureDefaults(args)
.ConfigureServices(services =>
{
// The console logger can result in duplicate logging.
List<ServiceDescriptor> toRemove = services
.Where(d => d.ServiceType == typeof(ILoggerProvider)
&& d.ImplementationType == typeof(ConsoleLoggerProvider))
.ToList();

foreach (var descriptor in toRemove)
{
services.Remove(descriptor);
}
})
.ConfigureFunctionsWorkerDefaults();

_functionsWorkerApplicationBuilder = InitializeHosting(_bootstrapHostBuilder);
}
Expand Down

0 comments on commit 34284c6

Please sign in to comment.