Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LogFactory - GetLogger should null-check logger name #3332

Merged
merged 1 commit into from
Apr 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/NLog/LogFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,9 @@ public void ResetCandidateConfigFilePath()

private Logger GetLoggerThreadSafe(string name, Type loggerType)
{
if (name == null)
throw new ArgumentNullException(nameof(name), "Name of logger cannot be null");

LoggerCacheKey cacheKey = new LoggerCacheKey(name, loggerType ?? typeof(Logger));

lock (_syncRoot)
Expand Down
7 changes: 7 additions & 0 deletions tests/NLog.UnitTests/LogFactoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -384,5 +384,12 @@ public void SuspendAndResumeLogging_OutOfOrder()
factory.ResumeLogging();
Assert.True(factory.IsLoggingEnabled());
}

[Fact]
public void LogFactory_GetLoggerWithNull_ShouldThrow()
{
LogFactory factory = new LogFactory();
Assert.Throws<ArgumentNullException>(() => factory.GetLogger(null));
}
}
}