1212// ------------------------------------------------------------------------
1313
1414using System ;
15+ using System . Linq ;
1516using System . Net . Http ;
1617using Microsoft . Extensions . Configuration ;
1718using Microsoft . Extensions . DependencyInjection ;
1819using Microsoft . Extensions . DependencyInjection . Extensions ;
20+ using Microsoft . Extensions . Logging ;
1921
2022namespace Dapr . Workflow ;
2123
@@ -40,6 +42,19 @@ public static IServiceCollection AddDaprWorkflow(
4042 serviceCollection . AddDaprClient ( lifetime : lifetime ) ;
4143 serviceCollection . AddHttpClient ( ) ;
4244 serviceCollection . AddHostedService < WorkflowLoggingService > ( ) ;
45+
46+ // Configure default logging levels for the DurableTask packages (can be overridden by consumer in appsettings.json)
47+ serviceCollection . Configure < LoggerFilterOptions > ( options =>
48+ {
49+ if ( ! HasExistingFilter ( options , "Dapr.DurableTask.Grpc" ) )
50+ options . AddFilter ( "Dapr.DurableTask.Grpc" , LogLevel . Error ) ;
51+ if ( ! HasExistingFilter ( options , "Dapr.DurableTask.Client.Grpc" ) )
52+ options . AddFilter ( "Dapr.DurableTask.Client.Grpc" , LogLevel . Error ) ;
53+ if ( ! HasExistingFilter ( options , "Dapr.DurableTask.Worker" ) )
54+ options . AddFilter ( "Dapr.DurableTask.Worker" , LogLevel . Error ) ;
55+ if ( ! HasExistingFilter ( options , "Dapr.DurableTask.Worker.Grpc" ) )
56+ options . AddFilter ( "Dapr.DurableTask.Worker.Grpc" , LogLevel . Error ) ;
57+ } ) ;
4358
4459 switch ( lifetime )
4560 {
@@ -73,4 +88,7 @@ public static IServiceCollection AddDaprWorkflow(
7388
7489 return serviceCollection ;
7590 }
91+
92+ private static bool HasExistingFilter ( LoggerFilterOptions options , string categoryName )
93+ => options . Rules . Any ( rule => rule . CategoryName == categoryName ) ;
7694}
0 commit comments