Skip to content

Commit

Permalink
LogFactory - GetLogger should validate name of logger (#3332)
Browse files Browse the repository at this point in the history
  • Loading branch information
snakefoot authored and 304NotModified committed Apr 24, 2019
1 parent 3c16e69 commit ea6f665
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
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));
}
}
}

0 comments on commit ea6f665

Please sign in to comment.