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

Option to disable OmexLogger #611

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

Gnol-VN
Copy link
Member

@Gnol-VN Gnol-VN commented Sep 29, 2023

Context

We introduce a setting Monitoring:OmexLoggingEnabled to allow consumers to enable or disable default OmexLogger (via Microsoft EventSource). Consumer can now register their custom logging provider, for example, OpenTelemetry or NLog.

Usage

The default setting of Monitoring:OmexLoggingEnabled is True.
If the setting is not provided, OmexLogger will be used as default

@Gnol-VN Gnol-VN requested a review from a team as a code owner September 29, 2023 13:55
@@ -29,7 +29,7 @@ private static ILoggingBuilder LoadInitializationLogger(this ILoggingBuilder bui
builder.AddConsole();
}

builder.AddOmexLogging();
builder.AddOmexLogging(null!); // Because this method cannot access HostBuilder's configuration.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that this change is breaking legacy logging for service initialization, it doesn't meet its own goal.

@@ -41,7 +41,7 @@ public static class HostBuilderExtensions
/// <summary>
/// Registering Dependency Injection classes that will provide Service Fabric specific information for logging
/// </summary>
public static IServiceCollection AddOmexServiceFabricDependencies<TContext>(this IServiceCollection collection)
public static IServiceCollection AddOmexServiceFabricDependencies<TContext>(this IServiceCollection collection, HostBuilderContext? hostBuilderContext)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this approach.
It is messy.
Given that it is a breaking change for Initialization Logger, I'd be in flavor of making it a fully breaking change - updating the package version would be disabling the old logger. Since both approaches would require a code change and deployment to release, there is no release operational difference.
The main difference is that downstream consumers would need to be aware of the breaking change in the package update.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, define extra extension methods where one adds the new dependencies and the other adds the old dependencies, then move the configuration handling back to the service and out of the dependency registration extensions.

Copy link
Contributor

@AndreyTretyak AndreyTretyak Oct 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be in faivour of doing breaking change and making AddOmexServiceFabricDependencies an extension on HostBuilderContext, since pattern of optional parameter super unusial and easy to miss for user, also HostBuilderContext contains IServiceCollection in it. We can still keep old extension method if absolutly needed but mark it as obsolete with an explanation of why change needed.

serviceCollection.AddLogging();

const string settingName = "Monitoring:OmexLoggingEnabled";
bool isEventSourceLoggingEnabled = bool.Parse(context?.Configuration.GetSection(settingName).Get<string>() ?? "true");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this works exactly like this, but I would expect something simular to this code should be possible, could you please check?

Suggested change
bool isEventSourceLoggingEnabled = bool.Parse(context?.Configuration.GetSection(settingName).Get<string>() ?? "true");
bool isEventSourceLoggingEnabled = context?.Configuration.GetSection(settingName).Get<bool>(true);

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.

3 participants