csharp-language-server-protocol
csharp-language-server-protocol copied to clipboard
Nullpointer Exception when using WithLoggerFactory
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();
}