diff --git a/src/Hosting.Services/HostBuilderExtensions.cs b/src/Hosting.Services/HostBuilderExtensions.cs
index 9990d5444..8e76f1657 100644
--- a/src/Hosting.Services/HostBuilderExtensions.cs
+++ b/src/Hosting.Services/HostBuilderExtensions.cs
@@ -23,25 +23,41 @@ public static class HostBuilderExtensions
///
/// Configures host to run service fabric stateless service with initialized Omex dependencies
///
+ /// Host builder
+ /// Service name
+ /// Action to configure Service fabric Host
+ /// Disable OmexLogger if you want to use your custom logger, eg: OpenTelemetry
+ /// Host builder
public static IHost BuildStatelessService(
this IHostBuilder builder,
string serviceName,
- Action> builderAction) =>
- builder.BuildServiceFabricService(serviceName, builderAction);
+ Action> builderAction,
+ bool disableOmexLogging = false) =>
+ builder.BuildServiceFabricService(serviceName, builderAction, disableOmexLogging);
///
/// Configures host to run service fabric stateful service with initialized Omex dependencies
///
+ /// Host builder
+ /// Service name
+ /// Action to configure Service fabric Host
+ /// Disable OmexLogger if you want to use your custom logger, eg: OpenTelemetry
+ /// Host builder
public static IHost BuildStatefulService(
this IHostBuilder builder,
string serviceName,
- Action> builderAction) =>
- builder.BuildServiceFabricService(serviceName, builderAction);
+ Action> builderAction,
+ bool disableOmexLogging = false) =>
+ builder.BuildServiceFabricService(serviceName, builderAction, disableOmexLogging);
///
/// Registering Dependency Injection classes that will provide Service Fabric specific information for logging
///
- public static IServiceCollection AddOmexServiceFabricDependencies(this IServiceCollection collection)
+ /// Service collection for DI
+ /// Disable OmexLogger if you want to use your custom logger, eg: OpenTelemetry
+ /// Service collection for DI after adding Service Fabric specific information for logging
+ public static IServiceCollection AddOmexServiceFabricDependencies(this IServiceCollection collection,
+ bool disableOmexLogging = false)
where TContext : ServiceContext
{
bool isStatefulService = typeof(StatefulServiceContext).IsAssignableFrom(typeof(TContext));
@@ -60,13 +76,14 @@ public static IServiceCollection AddOmexServiceFabricDependencies(this
collection.TryAddSingleton();
collection.TryAddSingleton();
- return collection.AddOmexServices();
+ return collection.AddOmexServices(disableOmexLogging);
}
private static IHost BuildServiceFabricService(
this IHostBuilder builder,
string serviceName,
- Action> builderAction)
+ Action> builderAction,
+ bool disableOmexLogging = false)
where TRunner : OmexServiceRegistrator
where TService : IServiceFabricService
where TContext : ServiceContext
@@ -92,7 +109,7 @@ private static IHost BuildServiceFabricService(
{
options.ServiceTypeName = serviceName;
})
- .AddOmexServiceFabricDependencies()
+ .AddOmexServiceFabricDependencies(disableOmexLogging)
.AddSingleton()
.AddHostedService();
})
diff --git a/src/Hosting/ServiceCollectionExtensions.cs b/src/Hosting/ServiceCollectionExtensions.cs
index 44e1d8cb2..3f9c3fdad 100644
--- a/src/Hosting/ServiceCollectionExtensions.cs
+++ b/src/Hosting/ServiceCollectionExtensions.cs
@@ -16,18 +16,31 @@ public static class ServiceCollectionExtensions
{
///
/// Add Omex Logging and ActivitySource dependencies
+ /// Host builder
+ /// Disable OmexLogger if you want to use your custom logger, eg: OpenTelemetry
///
- public static IHostBuilder AddOmexServices(this IHostBuilder builder) =>
+ /// Host Builder
+ public static IHostBuilder AddOmexServices(this IHostBuilder builder, bool disableOmexLogging = false) =>
builder
- .ConfigureServices((context, collection) => collection.AddOmexServices());
+ .ConfigureServices((context, collection) => collection.AddOmexServices(disableOmexLogging));
///
/// Add Omex Logging and ActivitySource dependencies
///
- public static IServiceCollection AddOmexServices(this IServiceCollection collection) =>
- collection
- .AddOmexLogging()
- .AddOmexActivitySource();
+ /// Service Collection for DI
+ /// Disable OmexLogger if you want to use your custom logger, eg: OpenTelemetry
+ /// Service Collection
+ public static IServiceCollection AddOmexServices(this IServiceCollection collection, bool disableOmexLogging = false)
+ {
+ collection.AddOmexActivitySource();
+
+ if (!disableOmexLogging)
+ {
+ collection.AddOmexLogging();
+ }
+
+ return collection;
+ }
///
/// Add Omex Logging and ActivitySource dependencies