Merged
Conversation
Member
Author
|
Here's why the squiggles don't appear in Rider: https://youtrack.jetbrains.com/issue/RIDER-73394 |
Member
Author
|
I added a code fix that converts automatically from this: private static void Test()
{
_log.Info()
.Append("Foo ")
.Append(Guid.NewGuid(), "B")
.Append(" Bar")
.Log();
}to this: private static void Test()
{
_log.Info($"Foo {Guid.NewGuid():B} Bar");
}🙂 It needs a bit more work though. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I wanted to play a bit with Roslyn, and ZeroLog was a good candidate for some analyzers 🙂
Implicitly discarding a log message (if you forget to call
.Log()for instance) will cause an error:This works just like if every method that returns a
LogMessage(even user-defined ones) were marked with[MustUseReturnValue]. You need to discard the message explicitly if you intend to do so, for instance in helper methods:Passing a string interpolation to ZeroLog in language versions below C# 10 will cause
an errora warning:In older language versions, this would call
string.Formatand allocate. This screenshot is from VS, I don't know why Rider doesn't display the squiggles, but you'll still get a builderrorwarning.Note that in multi-targeted projects, you'll get an older language version by default for targets older than .NET 6.
I suppose you really don't want to allocate if you use ZeroLog, but maybe this should be a warning instead? 🤔
You'll get a warning if you reference ZeroLog in a project that uses a language version below C# 10. Maybe that's a bit too harsh, I don't know...That'sprobablyredundant with the previous check.The build will fail if you use ZeroLog with an SDK older than .NET 6 (or a Visual Studio older than 2022), since the analyzers wouldn't run.
This will merge into #44, but I opened a separate PR for feedback. Also, feel free to suggest a better wording for the error messages. 🙂