-
Notifications
You must be signed in to change notification settings - Fork 151
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
calling AddNlog() multi time, will add another Nlog provider #254
Comments
Pull Requests are always welcome |
Not sure if we can detect this. Someone looked at this? |
We can only do this by using our own factory (planned for v2) Currently we we call namespace Microsoft.Extensions.Logging
{
/// <summary>
/// Represents a type used to configure the logging system and create instances of <see cref="T:Microsoft.Extensions.Logging.ILogger" /> from
/// the registered <see cref="T:Microsoft.Extensions.Logging.ILoggerProvider" />s.
/// </summary>
public interface ILoggerFactory : IDisposable
{
/// <summary>
/// Creates a new <see cref="T:Microsoft.Extensions.Logging.ILogger" /> instance.
/// </summary>
/// <param name="categoryName">The category name for messages produced by the logger.</param>
/// <returns>The <see cref="T:Microsoft.Extensions.Logging.ILogger" />.</returns>
ILogger CreateLogger(string categoryName);
/// <summary>
/// Adds an <see cref="T:Microsoft.Extensions.Logging.ILoggerProvider" /> to the logging system.
/// </summary>
/// <param name="provider">The <see cref="T:Microsoft.Extensions.Logging.ILoggerProvider" />.</param>
void AddProvider(ILoggerProvider provider);
}
} |
Not sure replacing the default LoggerFactory is always a good idea. See also NLog/NLog.Web#235 But it will resolve this issue. And there is already an "empty" LoggerFactory available right now. |
Maybe the simple workaround is adding a new NLogProviderOptions called Maybe also change NLogLoggerFactory so when calling AddNLog() using NLog-provider, then one will replace the existing NLog-provider when |
Sounds good to me :)
AFAIK the NLogLoggerFactory is not used, but this is also fine to me |
Since |
on NLog.Extensions.Logging, ( 1.3.0)
ILoggerFactory Factory = new Microsoft.Extensions.Logging.LoggerFactory();
Factory .AddNlog();
Factory .AddNlog();
calling AddNlog() will add another NLog provider, resulting in same line being outputted in log file
What is the expected result?
calling AddNlog() multi time will not add another NLog provider
Did you checked the Internal log?
no
Please post full exception details (message, stacktrace, inner exceptions)
same line being outputted in log file, in direct proportion to how many time i have call AddNlog()
Are there any work arrounds? yes/no
yes
Is there a version in which it did worked?
No
Can you help us by writing an unit test?
yes
The text was updated successfully, but these errors were encountered: