Skip to content

Commit 7fe2868

Browse files
committed
lock around the entire dictionary read to prevent read/write out of sync
1 parent 8720d27 commit 7fe2868

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/Microsoft.Extensions.Logging.MSBuild/MSBuildLoggerProvider.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ public MSBuildLoggerProvider(TaskLoggingHelper loggingHelperToWrap)
2222

2323
public ILogger CreateLogger(string categoryName)
2424
{
25-
if (!_loggers.TryGetValue(categoryName, out var logger))
25+
lock (_loggers)
2626
{
27-
logger = new MSBuildLogger(categoryName, _loggingHelper, _scopeProvider);
28-
lock (_loggers)
27+
if (!_loggers.TryGetValue(categoryName, out var logger))
2928
{
29+
logger = new MSBuildLogger(categoryName, _loggingHelper, _scopeProvider);
3030
_loggers[categoryName] = logger;
3131
}
32+
return logger;
3233
}
33-
return logger;
3434
}
3535

3636
public void Dispose() { }

test/Microsoft.NET.Build.Containers.IntegrationTests/PackageTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ public void SanityTest_NET_Build_ContainersDependencies()
4949
};
5050
IReadOnlyList<string> knownProjectReferences = new List<string>()
5151
{
52-
"..\\..\\Cli\\Microsoft.DotNet.Cli.Utils\\Microsoft.DotNet.Cli.Utils.csproj"
52+
"..\\..\\Cli\\Microsoft.DotNet.Cli.Utils\\Microsoft.DotNet.Cli.Utils.csproj",
53+
"..\\..\\Microsoft.Extensions.Logging.MSBuild\\Microsoft.Extensions.Logging.MSBuild.csproj"
5354
};
5455

5556
string projectFilePath = Path.Combine(TestContext.Current.TestExecutionDirectory, "Container", "ProjectFiles", "Microsoft.NET.Build.Containers.csproj");

0 commit comments

Comments
 (0)