Code Monkey home page Code Monkey logo

rebus.serilog's Introduction

Rebus.Serilog

install from nuget

Provides a Serilog logging integration for Rebus.


Do it like this if you just want Rebus to use your global Serilog logger directly:

Configure.With(...)
	.Logging(l => l.Serilog())
	.Transport(t => t.Use(...))
	.(...)
	.Start();

or like this if you want to customize it:

var logger = Log.ForContext("queue", queueName);

Configure.With(...)
	.Logging(l => l.Serilog(logger))
	.Transport(t => t.Use(..., queueName))
	.(...)
	.Start();

Initialize your Serilog logging with Rebus' correlation ID enricher if you'd like the correlation ID of handled messages to be added automatically to all log output generated from message handlers:

Log.Logger = new LoggerConfiguration()
    .WriteTo.(...)
    .Enrich.WithRebusCorrelationId("CorrelationId")
    .CreateLogger();

and then either use real structured logging (e.g. to an aggregator like Elastic), or remember to include it in your output template (here shown with ColoredConsole):

//                                                                                  ๐Ÿ‘‡
Log.Logger = new LoggerConfiguration()
	.WriteTo.ColoredConsole(outputTemplate: "{Timestamp:HH:mm:ss} {Level:u3} ({CorrelationId}) {Message}{NewLine}{Exception}")
	.(...)

rebus.serilog's People

Contributors

mookid8000 avatar rsivanov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

rebus.serilog's Issues

Rebus not using global serilog instance?

We have a asp.net core 3 web api which is listening to azure servicebus queues using Rebus. We have setup serilog according to the setup guides, but it seems that Rebus creates its own instance of ILogger instead of using the one we create in Program.cs.

We have tried getting the current instance from DI like below, but it does not seem to work.

var logger = services.BuildServiceProvider().GetService();

services.AddRebus((options, serviceProvider) => options
.Logging(l => l.Serilog(logger))
.Transport(t => t.UseAzureServiceBus(configuration["RebusConfig:AzureServiceBusConnectionString"], configuration["RebusConfig:Order:InputQueueName"]).AutomaticallyRenewPeekLock())

Is there someway to make sure Rebus uses the same serilog instance as the rest of the app?

The problem that this makes is that we have a Agent running on the server which injects traceid and such into the logcontext, which only works with logs outside of Rebus with this setup.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.