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

NLog variables are not threadsafe #2960

Closed
304NotModified opened this issue Oct 14, 2018 · 14 comments · Fixed by #4240
Closed

NLog variables are not threadsafe #2960

304NotModified opened this issue Oct 14, 2018 · 14 comments · Fixed by #4240
Milestone

Comments

@304NotModified
Copy link
Member

@snakefoot I see your recommendation for gdc over var,

e.g.

If needing to modify global variables at runtime, then it is recommended to use the GDC layout renderer instead. Because NLog variables are not threadsafe, and should be seen as readonly variables. Also GDC will behave correctly if LoggingConfiguration should change (or reloaded).

Is there something we could do to make the current nlog variables threadsafe? A lot of users find the variables more natural to use.

@snakefoot
Copy link
Contributor

snakefoot commented Oct 14, 2018 via email

@304NotModified
Copy link
Member Author

Maybe,

But even we could give the nlog variables a GDC` under the hood? That would solve the issue?

@snakefoot
Copy link
Contributor

snakefoot commented Oct 15, 2018 via email

@snakefoot
Copy link
Contributor

snakefoot commented Oct 18, 2018 via email

@snakefoot
Copy link
Contributor

snakefoot commented Oct 27, 2018

I guess when support for JsonLayout is added (Or CsvLayout), then the Variables-dictionary (with SimpleLayout) will be made obsolete. See also #1312

Would prefer that the Variables remained pure-string-blobs (as they were originally). And one parsed the blob on every lookup (and performed recursive expansions of variables on every lookup). One could of course do caching so only doing the recursion expansion if variables had changed since last lookup.

Also funny how NLog expects that the insert order of variables is guaranteed stable. As NLog expects to expand variables in the order they are declared. But Dictionary / ConcurrentDictionary makes no promise about enumerating their items in the order they were inserted (Dictionary-class tries really hard to behave like it though). One should probably be careful with just replacing Dictionary with ConcurrentDictionary.

@304NotModified
Copy link
Member Author

I guess when support for JsonLayout is added (Or CsvLayout), then the Variables-dictionary (with SimpleLayout) will be made obsolete. See also #1312

What do you mean? Should we do #1312, or should we skip that?

@snakefoot
Copy link
Contributor

What do you mean? Should we do #1312, or should we skip that?

When implementing support for JsonLayout and CsvLayout in NLog-variables, then it will require new a interface. This new interface can then implement a threadsafe dictionary, that is backward compatible with the old one.

@304NotModified
Copy link
Member Author

You mean, it's already a breaking change and so we could fix this structural?

@snakefoot
Copy link
Contributor

You mean, it's already a breaking change and so we could fix this structural?

The new implementation that handles JsonLayout and CsvLayout will ofcourse introduce a new interface (that hopefully fixes all known issues). Then there is an exercise in trying to support the old existing interface to avoid any breaking changes.

Not sure I understand the meaning of fix this structural.

@304NotModified 304NotModified self-assigned this Nov 5, 2018
@304NotModified 304NotModified removed their assignment Dec 28, 2018
@304NotModified
Copy link
Member Author

304NotModified commented Mar 18, 2019

I was thinking, this advice, does it also count when not using layout renderers inside the value?

e.g.

<variable name="user" value="admin" />

@snakefoot
Copy link
Contributor

Well I only wrote the advice for the ${var}-layoutrenderer wiki-page.

@snakefoot
Copy link
Contributor

snakefoot commented Jun 9, 2019

Btw. this issue has been closed without variables have become threadsafe to use (Only threadsafe to update)

@304NotModified
Copy link
Member Author

Were here some specific steps we should do?

@snakefoot
Copy link
Contributor

One could wrap Layouts that are not threadsafe by default in a special Layout that uses a lock-object.

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

Successfully merging a pull request may close this issue.

2 participants