Skip to content

feat(elastic): optional configureLogger hook for extra Serilog sinks - #28

Merged
samerzughul merged 1 commit into
mainfrom
ahmad/serilog-configure-hook
Oct 11, 2026
Merged

samerzughul merged 1 commit into
mainfrom
ahmad/serilog-configure-hook

Conversation

@AhmadRAbuhussein

Copy link
Copy Markdown
Contributor

Summary

  • UseSwElasticSearchLogger gets an optional Action<HostBuilderContext, LoggerConfiguration> configureLogger. It runs after the library's own configuration (level, enrichers, console, debug, Elasticsearch data stream), so an app can add more sinks or enrichers.
  • Why: UseSerilog replaces the .NET logging pipeline, so an ILoggerProvider registered elsewhere, such as Sentry's from UseSentry(), never receives ILogger calls. Without a hook, apps using this library can't send logged errors to Sentry. Mealivery's API only reported request exceptions; errors in bus consumers and hosted services were invisible.
  • README: documents the parameter with a Sentry example.

Compatibility

  • Optional, defaults to null → existing calls (UseSwElasticSearchLogger() / UseSwElasticSearchLogger(o => ...)) behave exactly as before.
  • The callback can only add to the configuration; the library's sinks, retention and enrichers are untouched.
  • New method signature → consumers just rebuild against the new version.

Usage

builder.Host.UseSwElasticSearchLogger(configureLogger: (_, cfg) =>
    cfg.WriteTo.Sentry(o =>
    {
        o.InitializeSdk = false; // already initialized by UseSentry
        o.MinimumEventLevel = LogEventLevel.Error;
    }));

Test plan

  • dotnet build of SW.Logger.ElasticSearch
  • Packed locally and built mealivery-api against it with the Sentry sink
  • After publish: mealivery-api on staging logs to Elasticsearch as before and sends errors to Sentry

UseSerilog replaces the .NET logging pipeline, so a logging provider
registered elsewhere (e.g. Sentry's) never receives an app's logs. The
new optional configureLogger callback runs after the built-in sinks, so
an app can add its own, such as Sentry. Existing callers are unchanged.
@coderabbitai

coderabbitai Bot commented Oct 11, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: Repository: simplify9/coderabbit/.coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 28728c95-6fa6-45e5-ad4a-047ec4c3139f

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@samerzughul
samerzughul merged commit dcdac93 into main Oct 11, 2026
4 checks passed
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

Successfully merging this pull request may close these issues.

2 participants