Do I have to explicitly dispose a Microsoft.Extensions.Logging.BeginScope?

355 views Asked by At

I have got a series of hangfire jobs and I put in the constructor this piece of code, to use with Serilog/Seq

 public CheckoutExternalToursBookingJob(
      ...omiss...
        ILogger<CheckoutExternalToursBookingJob> logger,
        IEmailSender emailSender)
    {
      ...omiss...
        _logger = logger;
        _emailSender = emailSender;

        _logger.BeginScope(new Dictionary<string, object>
        {
            [CoreConstants.ApplicationName] = CoreConstants.HangFireApplicationName,
            [CoreConstants.HangFireJob] = JobName
        });
    }

Now I use this to have for all the _logger.* logs that information filled.

Since the BeginScope returns an IDisposable should I save it to a local variable, then implement in my jobs the IDisposable interface and do scope.Dispose()?

0

There are 0 answers