-
Notifications
You must be signed in to change notification settings - Fork 39
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
base: main
Are you sure you want to change the base?
Changes from all commits
11bdfae
a49b7ab
d6aa6bd
15cc307
5fed5bc
37e68df
e1240f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
return builder; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,8 +1,10 @@ | ||||||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||||||
// Licensed under the MIT license. | ||||||
|
||||||
using Microsoft.Extensions.Configuration; | ||||||
using Microsoft.Extensions.DependencyInjection; | ||||||
using Microsoft.Extensions.DependencyInjection.Extensions; | ||||||
using Microsoft.Extensions.Hosting; | ||||||
using Microsoft.Extensions.Logging; | ||||||
using Microsoft.Omex.Extensions.Abstractions.Activities.Processing; | ||||||
using Microsoft.Omex.Extensions.Abstractions.ExecutionContext; | ||||||
|
@@ -29,23 +31,32 @@ public static IServiceCollection AddOmexServiceContext<TServiceContext>(this ISe | |||||
/// Adds Omex event logger to the factory | ||||||
/// </summary> | ||||||
/// <param name="builder">The extension method argument</param> | ||||||
public static ILoggingBuilder AddOmexLogging(this ILoggingBuilder builder) | ||||||
/// <param name="context">HostBuilderContext to access Configuration</param> | ||||||
public static ILoggingBuilder AddOmexLogging(this ILoggingBuilder builder, HostBuilderContext? context) | ||||||
{ | ||||||
builder.Services.AddOmexLogging(); | ||||||
builder.Services.AddOmexLogging(context); | ||||||
return builder; | ||||||
} | ||||||
|
||||||
/// <summary> | ||||||
/// Adds Omex event logger to the factory | ||||||
/// </summary> | ||||||
/// <param name="serviceCollection">The extension method argument</param> | ||||||
/// <param name="context">HostBuilderContext to access Configuration</param> | ||||||
/// <returns>The <see cref="IServiceCollection"/> so that additional calls can be chained</returns> | ||||||
public static IServiceCollection AddOmexLogging(this IServiceCollection serviceCollection) | ||||||
public static IServiceCollection AddOmexLogging(this IServiceCollection serviceCollection, HostBuilderContext? context) | ||||||
{ | ||||||
serviceCollection.AddLogging(); | ||||||
|
||||||
serviceCollection.TryAddTransient<IServiceContext, EmptyServiceContext>(); | ||||||
serviceCollection.TryAddTransient<IExecutionContext, BaseExecutionContext>(); | ||||||
serviceCollection.AddLogging(); | ||||||
|
||||||
const string settingName = "Monitoring:OmexLoggingEnabled"; | ||||||
bool isEventSourceLoggingEnabled = bool.Parse(context?.Configuration.GetSection(settingName).Get<string>() ?? "true"); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||||||
if (!isEventSourceLoggingEnabled) | ||||||
{ | ||||||
return serviceCollection; | ||||||
} | ||||||
|
||||||
serviceCollection.TryAddTransient<IExternalScopeProvider, LoggerExternalScopeProvider>(); | ||||||
|
||||||
serviceCollection.TryAddSingleton(_ => OmexLogEventSource.Instance); | ||||||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 onHostBuilderContext
, since pattern of optional parameter super unusial and easy to miss for user, alsoHostBuilderContext
containsIServiceCollection
in it. We can still keep old extension method if absolutly needed but mark it as obsolete with an explanation of why change needed.