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

[QUESTION] - customization of Elastic.Extensions.Logging #412

Open
PCDiver opened this issue Jul 11, 2024 · 2 comments · May be fixed by #448
Open

[QUESTION] - customization of Elastic.Extensions.Logging #412

PCDiver opened this issue Jul 11, 2024 · 2 comments · May be fixed by #448

Comments

@PCDiver
Copy link

PCDiver commented Jul 11, 2024

Hi all,

I'm working on a logger for .NET6 (and .NET Standard 2.0) that logs directly to Elasticsearch. We currently use serilog, but I would like to reduce dependencies on other frameworks.

I looked at the source code for Elastic.Extensions.Logging and I cannot find any "customization" options. A lot of static methods, almost no overrides, no delegates to change LogEvents, ....

Here are some examples of logEvent manipulation that I was thinking of.:

  • How can we change the user name? Currently the name is obtained from "Thread.CurrentPrincipal?.Identity?.Name". This is not always correct. Sometimes ClaimsPrincipal needs to be used.
  • How can we add other "enrichers" (to keep with the Serilog terminology?
  • How can we customize error handling (like logging via another logger in case there is a problem with the Elistic logger.?

All information and feedback very welcome.

Peter

@Mpdreamz Mpdreamz linked a pull request Sep 18, 2024 that will close this issue
@Mpdreamz
Copy link
Member

I've opened #448 to address being able to to log event manipulation. This existed for Serilog already but not Extensions logging.

@Mpdreamz
Copy link
Member

How can we customize error handling (like logging via another logger in case there is a problem with the Elistic logger.

This one is a bit tougher to implement since at the time of instantiating of logging builder no fallback loggers are materialised.

Here's a quick example of how to be notified of elastic search export failures.

loggingBuilder.AddElasticsearch(options =>
{
	//options.BootstrapMethod = BootstrapMethod.Failure;
}, channel =>
{
	channel.ExportResponseCallback = (r, b) =>
		Console.WriteLine($"statusCode: {r.ApiCallDetails.HttpStatusCode} items: {b.Count} time since first write: {b.DurationSinceFirstWrite}");
});

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 a pull request may close this issue.

2 participants