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

Disable omex logger #574

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions src/Hosting.Services/HostBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,41 @@ public static class HostBuilderExtensions
/// <summary>
/// Configures host to run service fabric stateless service with initialized Omex dependencies
/// </summary>
/// <param name="builder">Host builder</param>
/// <param name="serviceName"> Service name</param>
/// <param name="builderAction">Action to configure Service fabric Host</param>
/// <param name="disableOmexLogging">Disable OmexLogger if you want to use your custom logger, eg: OpenTelemetry</param>
/// <returns>Host builder</returns>
public static IHost BuildStatelessService(
this IHostBuilder builder,
string serviceName,
Action<ServiceFabricHostBuilder<OmexStatelessService, StatelessServiceContext>> builderAction) =>
builder.BuildServiceFabricService<OmexStatelessServiceRegistrator, OmexStatelessService, StatelessServiceContext>(serviceName, builderAction);
Action<ServiceFabricHostBuilder<OmexStatelessService, StatelessServiceContext>> builderAction,
bool disableOmexLogging = false) =>
builder.BuildServiceFabricService<OmexStatelessServiceRegistrator, OmexStatelessService, StatelessServiceContext>(serviceName, builderAction, disableOmexLogging);

/// <summary>
/// Configures host to run service fabric stateful service with initialized Omex dependencies
/// </summary>
/// <param name="builder">Host builder</param>
/// <param name="serviceName"> Service name</param>
/// <param name="builderAction">Action to configure Service fabric Host</param>
/// <param name="disableOmexLogging">Disable OmexLogger if you want to use your custom logger, eg: OpenTelemetry</param>
/// <returns>Host builder</returns>
public static IHost BuildStatefulService(
this IHostBuilder builder,
string serviceName,
Action<ServiceFabricHostBuilder<OmexStatefulService, StatefulServiceContext>> builderAction) =>
builder.BuildServiceFabricService<OmexStatefulServiceRegistrator, OmexStatefulService, StatefulServiceContext>(serviceName, builderAction);
Action<ServiceFabricHostBuilder<OmexStatefulService, StatefulServiceContext>> builderAction,
bool disableOmexLogging = false) =>
builder.BuildServiceFabricService<OmexStatefulServiceRegistrator, OmexStatefulService, StatefulServiceContext>(serviceName, builderAction, disableOmexLogging);

/// <summary>
/// Registering Dependency Injection classes that will provide Service Fabric specific information for logging
/// </summary>
public static IServiceCollection AddOmexServiceFabricDependencies<TContext>(this IServiceCollection collection)
/// <param name="collection">Service collection for DI</param>
/// <param name="disableOmexLogging">Disable OmexLogger if you want to use your custom logger, eg: OpenTelemetry</param>
/// <returns>Service collection for DI after adding Service Fabric specific information for logging</returns>
public static IServiceCollection AddOmexServiceFabricDependencies<TContext>(this IServiceCollection collection,
bool disableOmexLogging = false)
where TContext : ServiceContext
{
bool isStatefulService = typeof(StatefulServiceContext).IsAssignableFrom(typeof(TContext));
Expand All @@ -60,13 +76,14 @@ public static IServiceCollection AddOmexServiceFabricDependencies<TContext>(this

collection.TryAddSingleton<IServiceContext, OmexServiceFabricContext>();
collection.TryAddSingleton<IExecutionContext, ServiceFabricExecutionContext>();
return collection.AddOmexServices();
return collection.AddOmexServices(disableOmexLogging);
}

private static IHost BuildServiceFabricService<TRunner, TService, TContext>(
this IHostBuilder builder,
string serviceName,
Action<ServiceFabricHostBuilder<TService, TContext>> builderAction)
Action<ServiceFabricHostBuilder<TService, TContext>> builderAction,
bool disableOmexLogging = false)
where TRunner : OmexServiceRegistrator<TService, TContext>
where TService : IServiceFabricService<TContext>
where TContext : ServiceContext
Expand All @@ -92,7 +109,7 @@ private static IHost BuildServiceFabricService<TRunner, TService, TContext>(
{
options.ServiceTypeName = serviceName;
})
.AddOmexServiceFabricDependencies<TContext>()
.AddOmexServiceFabricDependencies<TContext>(disableOmexLogging)
.AddSingleton<IOmexServiceRegistrator, TRunner>()
.AddHostedService<OmexHostedService>();
})
Expand Down
25 changes: 19 additions & 6 deletions src/Hosting/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,31 @@ public static class ServiceCollectionExtensions
{
/// <summary>
/// Add Omex Logging and ActivitySource dependencies
/// <param name="builder">Host builder</param>
/// <param name="disableOmexLogging">Disable OmexLogger if you want to use your custom logger, eg: OpenTelemetry</param>
/// </summary>
public static IHostBuilder AddOmexServices(this IHostBuilder builder) =>
/// <returns>Host Builder</returns>
public static IHostBuilder AddOmexServices(this IHostBuilder builder, bool disableOmexLogging = false) =>
builder
.ConfigureServices((context, collection) => collection.AddOmexServices());
.ConfigureServices((context, collection) => collection.AddOmexServices(disableOmexLogging));

/// <summary>
/// Add Omex Logging and ActivitySource dependencies
/// </summary>
public static IServiceCollection AddOmexServices(this IServiceCollection collection) =>
collection
.AddOmexLogging()
.AddOmexActivitySource();
/// <param name="collection">Service Collection for DI</param>
/// <param name="disableOmexLogging">Disable OmexLogger if you want to use your custom logger, eg: OpenTelemetry</param>
/// <returns>Service Collection</returns>
public static IServiceCollection AddOmexServices(this IServiceCollection collection, bool disableOmexLogging = false)
{
collection.AddOmexActivitySource();

if (!disableOmexLogging)
{
collection.AddOmexLogging();
}

return collection;
}

/// <summary>
/// Add Omex Logging and ActivitySource dependencies
Expand Down