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

Use source generated LoggerMessage #1651

Open
woksin opened this issue Jun 5, 2022 · 3 comments
Open

Use source generated LoggerMessage #1651

woksin opened this issue Jun 5, 2022 · 3 comments

Comments

@woksin
Copy link
Contributor

woksin commented Jun 5, 2022

Is it time to start gradually moving over to using Microsoft's source generated LoggerMessage? With the source generated logger message you get multiple things for free. Better performance and less allocations, no need to check if log level is enabled and hiding the actual log messages behind method-names (i.e LogThatXFailed(error)).

Technically I don't think that there is a problem introducing given the target frameworks of these projects.

@woksin
Copy link
Contributor Author

woksin commented Jun 5, 2022

This is obviously not something that needs to be done in one big-bang. In my experience it is smart to just decide on starting somewhere and sticking to it, then it's also easier to continue using it for new log-statements.

In terms of performance the best place to start would be where logging happens frequently, if you have a suggestion I would be happy to start this journey

@alexeyzimarev
Copy link
Member

alexeyzimarev commented Jun 5, 2022

What I did in Eventuous is to use the EventSource instead, and add an extension for the application builder, which adds a listener that dumps messages produced by the EventSource to ILogger. EventSource is very fast, although limited in functionality, and, if allows a more structured approach for logging like

            catch (Exception e) {
                Log.UnableToLoadAggregate<T>(streamName, e);
                throw;
            }

I see that the ILogger source generator uses the same principle by defining a "DSL" for logging and use attributes for the message template and level. With EventSource it looks like this

    [Event(TypeMapRegisteredId, Message = "Type {0} registered as {1}", Level = EventLevel.Verbose)]
    public void TypeMapRegistered(string type, string typeName) {
        if (IsEnabled(EventLevel.Verbose, EventKeywords.All)) WriteEvent(TypeMapRegisteredId, type, typeName);
    }

@rogeralsing
Copy link
Contributor

I'm all for giving the new source-generated logging a try.
It would be interesting to see it in an isolated case first. just to get some idea of the look and feel of it

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

No branches or pull requests

3 participants