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

Add small example snippet for adding CorrelationId to logs #100

Open
svdHero opened this issue Jan 20, 2021 · 0 comments
Open

Add small example snippet for adding CorrelationId to logs #100

svdHero opened this issue Jan 20, 2021 · 0 comments

Comments

@svdHero
Copy link

svdHero commented Jan 20, 2021

Hi there,

the wiki states

AddToLoggingScope - Add the correlation ID value to the logger scope for all requests. When true the value of the correlation ID will be added to the logger scope payload.

However, I am new to the whole .NET logging framework and I am not familiar with logger scopes. Could you provide a small code snippet that shows how I can get the Correlationid in each entry of my console logger automagically? That would be really great.

So far I set up my logging using

            Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseStartup<Startup>();
                })
                .ConfigureLogging(logging =>
                {
                    logging.ClearProviders();
                    logging.AddSimpleConsole(options =>
                    {
                        options.TimestampFormat = "'['yyyy'-'MM'-'dd HH':'mm':'ss']' ";
                        options.UseUtcTimestamp = true;
                        options.IncludeScopes = true;
                        options.SingleLine = true;
                    });
                });

All I want is a console logger that logs a line with Timestamp, LogLevel, CategoryName (=LoggerName???), CorrelationId and LogMessage.

I would be really grateful for any example, because the beauty of this middleware seems to be that it is an easier entrypoint for beginners like myself than the whole Activity and logging jungle.

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