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

Nullpointer Exception when using WithLoggerFactory #913

Open
hahoyer opened this issue Dec 16, 2022 · 0 comments
Open

Nullpointer Exception when using WithLoggerFactory #913

hahoyer opened this issue Dec 16, 2022 · 0 comments

Comments

@hahoyer
Copy link

hahoyer commented Dec 16, 2022

If I use a separate logger factory with its own ILogger interface implementation for the WithLoggerFactory call, then it is not possible to simply return zero in the implementation of the ILogger.BeginScope function.
This leads to a null pointer exception in TimeLoggerExtensions.Disposable.Dispose, because it is not checked here whether the member variable "Disposable" is set at all.
You can work around this by returning "new CompositeDisposable()" in ILogger.BeginScope, for example.
But you have to know that. This is not recognisable from the error message. I have not found anything about this in the documentation.
My suggestion would be to simply modify the Dispose function:

            public void Dispose()
            {
                _sw.Stop();
                _action(_sw.ElapsedMilliseconds);
                _disposable?.Dispose();
            }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant