Cysharp / ZLogger

Zero Allocation Text/Structured Logger for .NET with StringInterpolation and Source Generator, built on top of a Microsoft.Extensions.Logging.
MIT License
1.11k stars 79 forks source link

Make use of "Interceptors" feature from C# 12 (Experimental) #138

Closed biqas closed 5 months ago

biqas commented 6 months ago

Hi,

can you not make use of interceptors from C# 12? Then the method signature would stay same and no changes would be required to use ZLogger or not? Also, you would stay compatible with Microsoft ILogger interface.

neuecc commented 6 months ago

Interesting proposal. However, I'm concerned that this might end up being a less recommended approach due to the significantly different behavior during String Interpolation.

biqas commented 6 months ago

I don't think this will be an issue. dotnet team is also making use of it to rewrite/replace/intercept the routing map methods to make them aot friendly.

hadashiA commented 5 months ago

ILogger.Log($"Hello, {name}") and ILogger.ZLog($"Hello, {name}") have the same interface, but different behavior.

The former just generates a string.
The latter recognizes variables like name and uses them for structured logging.

I don't think Routing.Map just applies optimizations and doesn't differ in this kind of behavior.

Wouldn't it be confusing to treat this transparently?