@@ -35,6 +35,8 @@ internal class UserCodeLoader
3535 {
3636 private const string UserInvokeException = "An exception occurred while invoking customer handler." ;
3737 private const string LambdaLoggingActionFieldName = "_loggingAction" ;
38+ private const string LambdaLoggingWithLevelActionFieldName = "_loggingWithLevelAction" ;
39+ private const string LambdaLoggingWithLevelAndExceptionActionFieldName = "_loggingWithLevelAndExceptionAction" ;
3840
3941 internal const string LambdaCoreAssemblyName = "Amazon.Lambda.Core" ;
4042
@@ -186,6 +188,82 @@ internal static void SetCustomerLoggerLogAction(Assembly coreAssembly, Action<st
186188 }
187189 }
188190
191+ internal static void SetCustomerLoggerLogAction ( Assembly coreAssembly , Action < string , string , object [ ] > loggingWithLevelAction , InternalLogger internalLogger )
192+ {
193+ if ( coreAssembly == null )
194+ {
195+ throw new ArgumentNullException ( nameof ( coreAssembly ) ) ;
196+ }
197+
198+ if ( loggingWithLevelAction == null )
199+ {
200+ throw new ArgumentNullException ( nameof ( loggingWithLevelAction ) ) ;
201+ }
202+
203+ internalLogger . LogDebug ( $ "UCL : Retrieving type '{ Types . LambdaLoggerTypeName } '") ;
204+ var lambdaILoggerType = coreAssembly . GetType ( Types . LambdaLoggerTypeName ) ;
205+ if ( lambdaILoggerType == null )
206+ {
207+ throw LambdaExceptions . ValidationException ( Errors . UserCodeLoader . Internal . UnableToLocateType , Types . LambdaLoggerTypeName ) ;
208+ }
209+
210+ internalLogger . LogDebug ( $ "UCL : Retrieving field '{ LambdaLoggingWithLevelActionFieldName } '") ;
211+ var loggingActionField = lambdaILoggerType . GetTypeInfo ( ) . GetField ( LambdaLoggingWithLevelActionFieldName , BindingFlags . NonPublic | BindingFlags . Static ) ;
212+ if ( loggingActionField == null )
213+ {
214+ throw LambdaExceptions . ValidationException ( Errors . UserCodeLoader . Internal . UnableToRetrieveField , LambdaLoggingWithLevelActionFieldName , Types . LambdaLoggerTypeName ) ;
215+ }
216+
217+ internalLogger . LogDebug ( $ "UCL : Setting field '{ LambdaLoggingWithLevelActionFieldName } '") ;
218+ try
219+ {
220+ loggingActionField . SetValue ( null , loggingWithLevelAction ) ;
221+ }
222+ catch ( Exception e )
223+ {
224+ throw LambdaExceptions . ValidationException ( e , Errors . UserCodeLoader . Internal . UnableToSetField ,
225+ Types . LambdaLoggerTypeName , LambdaLoggingWithLevelActionFieldName ) ;
226+ }
227+ }
228+
229+ internal static void SetCustomerLoggerLogAction ( Assembly coreAssembly , Action < string , Exception , string , object [ ] > loggingWithAndExceptionLevelAction , InternalLogger internalLogger )
230+ {
231+ if ( coreAssembly == null )
232+ {
233+ throw new ArgumentNullException ( nameof ( coreAssembly ) ) ;
234+ }
235+
236+ if ( loggingWithAndExceptionLevelAction == null )
237+ {
238+ throw new ArgumentNullException ( nameof ( loggingWithAndExceptionLevelAction ) ) ;
239+ }
240+
241+ internalLogger . LogDebug ( $ "UCL : Retrieving type '{ Types . LambdaLoggerTypeName } '") ;
242+ var lambdaILoggerType = coreAssembly . GetType ( Types . LambdaLoggerTypeName ) ;
243+ if ( lambdaILoggerType == null )
244+ {
245+ throw LambdaExceptions . ValidationException ( Errors . UserCodeLoader . Internal . UnableToLocateType , Types . LambdaLoggerTypeName ) ;
246+ }
247+
248+ internalLogger . LogDebug ( $ "UCL : Retrieving field '{ LambdaLoggingWithLevelAndExceptionActionFieldName } '") ;
249+ var loggingActionField = lambdaILoggerType . GetTypeInfo ( ) . GetField ( LambdaLoggingWithLevelAndExceptionActionFieldName , BindingFlags . NonPublic | BindingFlags . Static ) ;
250+ if ( loggingActionField == null )
251+ {
252+ throw LambdaExceptions . ValidationException ( Errors . UserCodeLoader . Internal . UnableToRetrieveField , LambdaLoggingWithLevelAndExceptionActionFieldName , Types . LambdaLoggerTypeName ) ;
253+ }
254+
255+ internalLogger . LogDebug ( $ "UCL : Setting field '{ LambdaLoggingWithLevelAndExceptionActionFieldName } '") ;
256+ try
257+ {
258+ loggingActionField . SetValue ( null , loggingWithAndExceptionLevelAction ) ;
259+ }
260+ catch ( Exception e )
261+ {
262+ throw LambdaExceptions . ValidationException ( e , Errors . UserCodeLoader . Internal . UnableToSetField ,
263+ Types . LambdaLoggerTypeName , LambdaLoggingWithLevelAndExceptionActionFieldName ) ;
264+ }
265+ }
266+
189267 /// <summary>
190268 /// Constructs customer-specified serializer, specified either on the method,
191269 /// the assembly, or not specified at all.
0 commit comments