@@ -95,39 +95,57 @@ public AWSLoggerCore(AWSLoggerConfig config, string logType)
9595 _config = config ;
9696 _logType = logType ;
9797
98- var awsConfig = new AmazonCloudWatchLogsConfig ( ) ;
99- if ( ! string . IsNullOrWhiteSpace ( _config . ServiceUrl ) )
98+ if ( config . PreconfiguredServiceClient == null )
10099 {
101- var serviceUrl = _config . ServiceUrl . Trim ( ) ;
102- awsConfig . ServiceURL = serviceUrl ;
103- if ( serviceUrl . StartsWith ( "http://" , StringComparison . OrdinalIgnoreCase ) )
100+ var awsConfig = new AmazonCloudWatchLogsConfig ( ) ;
101+ if ( ! string . IsNullOrWhiteSpace ( _config . ServiceUrl ) )
104102 {
105- awsConfig . UseHttp = true ;
103+ var serviceUrl = _config . ServiceUrl . Trim ( ) ;
104+ awsConfig . ServiceURL = serviceUrl ;
105+ if ( serviceUrl . StartsWith ( "http://" , StringComparison . OrdinalIgnoreCase ) )
106+ {
107+ awsConfig . UseHttp = true ;
108+ }
106109 }
107- }
108- else
109- {
110- if ( ! string . IsNullOrEmpty ( _config . Region ) )
110+ else
111111 {
112- awsConfig . RegionEndpoint = Amazon . RegionEndpoint . GetBySystemName ( _config . Region ) ;
112+ if ( ! string . IsNullOrEmpty ( _config . Region ) )
113+ {
114+ awsConfig . RegionEndpoint = Amazon . RegionEndpoint . GetBySystemName ( _config . Region ) ;
115+ }
113116 }
114- }
115117
116- if ( ! string . IsNullOrEmpty ( _config . AuthenticationRegion ) )
117- {
118- awsConfig . AuthenticationRegion = _config . AuthenticationRegion ;
119- }
118+ if ( ! string . IsNullOrEmpty ( _config . AuthenticationRegion ) )
119+ {
120+ awsConfig . AuthenticationRegion = _config . AuthenticationRegion ;
121+ }
122+
123+ _client = new Lazy < IAmazonCloudWatchLogs > ( ( ) =>
124+ {
125+ var credentials = DetermineCredentials ( config ) ;
126+ var client = new AmazonCloudWatchLogsClient ( credentials , awsConfig ) ;
127+
128+ client . BeforeRequestEvent += ServiceClientBeforeRequestEvent ;
129+ client . ExceptionEvent += ServiceClientExceptionEvent ;
120130
121- _client = new Lazy < IAmazonCloudWatchLogs > ( ( ) =>
131+ return client ;
132+ } ) ;
133+ }
134+ else
122135 {
123- var credentials = DetermineCredentials ( config ) ;
124- var client = new AmazonCloudWatchLogsClient ( credentials , awsConfig ) ;
136+ var preconfiguredClient = config . PreconfiguredServiceClient ;
137+ if ( preconfiguredClient is AmazonCloudWatchLogsClient preconfiguredClientImpl )
138+ {
139+ preconfiguredClientImpl . BeforeRequestEvent += ServiceClientBeforeRequestEvent ;
140+ preconfiguredClientImpl . ExceptionEvent += ServiceClientExceptionEvent ;
141+ }
125142
126- client . BeforeRequestEvent += ServiceClientBeforeRequestEvent ;
127- client . ExceptionEvent += ServiceClientExceptionEvent ;
128143
129- return client ;
130- } ) ;
144+ _client = new Lazy < IAmazonCloudWatchLogs > ( ( ) =>
145+ {
146+ return preconfiguredClient ;
147+ } ) ;
148+ }
131149
132150 StartMonitor ( ) ;
133151 RegisterShutdownHook ( ) ;
@@ -681,7 +699,7 @@ void ServiceClientBeforeRequestEvent(object sender, RequestEventArgs e)
681699 if ( args != null && args . Request is Amazon . Runtime . Internal . IAmazonWebServiceRequest internalRequest && ! internalRequest . UserAgentDetails . GetCustomUserAgentComponents ( ) . Contains ( userAgentString ) )
682700 {
683701 internalRequest . UserAgentDetails . AddUserAgentComponent ( userAgentString ) ;
684- }
702+ }
685703 }
686704
687705 void ServiceClientExceptionEvent ( object sender , ExceptionEventArgs e )
0 commit comments