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

After call AddNLog header is written twice #708

Closed
RomanSoloweow opened this issue Nov 20, 2023 · 11 comments
Closed

After call AddNLog header is written twice #708

RomanSoloweow opened this issue Nov 20, 2023 · 11 comments
Labels

Comments

@RomanSoloweow
Copy link

After call AddNLog header is written twice

Steps to reproduce

  1. Config FileTargets with header
  2. Enable WriteHeaderWhenInitialFileNotEmpty option
  3. Call AddNLog

After call AddNLog header is written twice. If you don't call AddNLog, everything works as expected

I don’t know what the reason could be, but it looks like AddNlog causes FileTarget to be reinitialized or creates its own using the same layout

@RomanSoloweow
Copy link
Author

@snakefoot can you check it please?

@snakefoot
Copy link
Contributor

snakefoot commented Nov 23, 2023

Could you include a minimal reproducable example in source-code? (Or even better an unit-test). Maybe also the output from NLog InternalLogger.

@snakefoot
Copy link
Contributor

Tried to reproduce based on you initial details. And failed to reproduce.

Succes with both NLog.config and LogManager.Setup().LoadConfiguration(...)

@RomanSoloweow
Copy link
Author

RomanSoloweow commented Nov 30, 2023

Could you send me the project with reproduction please? I will try to correct it completely with my logic

@snakefoot
Copy link
Contributor

snakefoot commented Nov 30, 2023 via email

RomanSoloweow added a commit to RomanSoloweow/NLog.Extensions.Logging that referenced this issue Dec 1, 2023
@RomanSoloweow
Copy link
Author

@snakefoot PR with reproduce: #709

@snakefoot
Copy link
Contributor

snakefoot commented Dec 3, 2023

When calling builder.AddNLog(logger.Factory.Configuration); then it forces AddNLog to re-assign the configuration (thus closing file-target and all filehandles, followed by re-initializing it again)

Try using builder.AddNLog(), which just installs NLog as Logging-Provider without re-assign of configuration.

@RomanSoloweow
Copy link
Author

I can't find a description of this anywhere. + It is not clear what other methods can lead to this. I think it's worth updating the documentation

@snakefoot
Copy link
Contributor

snakefoot commented Dec 5, 2023

I'm guessing that the behavior was seen as implicit, when calling AddNLog with input-parameter LoggingConfiguration that is meant to be New NLog config:

        /// <summary>
        /// Enable NLog as logging provider for Microsoft Extension Logging
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="configuration">New NLog config.</param>
        /// <returns>ILoggingBuilder for chaining</returns>
        public static ILoggingBuilder AddNLog(this ILoggingBuilder builder, LoggingConfiguration configuration)

But all improvements to documentation are always wellcome. Like the goal of preventing users from faling into traps.

@snakefoot
Copy link
Contributor

snakefoot commented Dec 5, 2023

@RomanSoloweow Created #710 that tries to improve the XML docs for AddNLog. Feedback is wellcome

@snakefoot
Copy link
Contributor

Closing issue, as the reason has been found. And #710 has been committed, which tries to improve XML-docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants