5
5
using System . Collections . Generic ;
6
6
using System . Linq ;
7
7
using System . Threading . Tasks ;
8
+ using Microsoft . Azure . WebJobs . Host ;
9
+ using Microsoft . Azure . WebJobs . Host . Listeners ;
8
10
using Microsoft . Azure . WebJobs . Logging ;
9
11
using Microsoft . Azure . WebJobs . Script . Configuration ;
10
12
using Microsoft . Azure . WebJobs . Script . WebHost ;
@@ -149,6 +151,22 @@ public void Log_Error_EmitsExpectedEvent()
149
151
_mockEventGenerator . VerifyAll ( ) ;
150
152
}
151
153
154
+ [ Theory ]
155
+ [ MemberData ( nameof ( FunctionExceptionDataProvider . TestCases ) , MemberType = typeof ( FunctionExceptionDataProvider ) ) ]
156
+ public void Log_FunctionException_EmitsExpectedEvent ( FunctionException functionException , string functionName )
157
+ {
158
+ string eventName = string . Empty ;
159
+ string functionInvocationId = string . Empty ;
160
+ string activityId = string . Empty ;
161
+
162
+ _mockEventGenerator . Setup ( p => p . LogFunctionTraceEvent ( LogLevel . Error , _subscriptionId , _websiteName , functionName , eventName , string . Empty , functionException . ToFormattedString ( ) , functionException . Message , functionException . InnerException . GetType ( ) . ToString ( ) , functionException . InnerException . Message , functionInvocationId , _hostInstanceId , activityId , _runtimeSiteName , _slotName , It . IsAny < DateTime > ( ) ) ) ;
163
+
164
+ ILogger localLogger = new SystemLogger ( _hostInstanceId , string . Empty , _mockEventGenerator . Object , _environment , _debugStateProvider . Object , null , new LoggerExternalScopeProvider ( ) , _appServiceOptions ) ;
165
+ localLogger . LogError ( functionException , functionException . Message ) ;
166
+
167
+ _mockEventGenerator . VerifyAll ( ) ;
168
+ }
169
+
152
170
[ Fact ]
153
171
public void Log_Sanitization ( )
154
172
{
@@ -291,5 +309,26 @@ public void AppEnvironment_Reset_OnSpecialization()
291
309
Assert . Equal ( "updatedslot" , evt . SlotName ) ;
292
310
Assert . Equal ( "updatedruntimesitename" , evt . RuntimeSiteName ) ;
293
311
}
312
+
313
+ public class FunctionExceptionDataProvider
314
+ {
315
+ public static IEnumerable < object [ ] > TestCases
316
+ {
317
+ get
318
+ {
319
+ yield return new object [ ] { new FunctionListenerException ( "Functions.TestFunction" , new Exception ( "Kaboom" ) ) , "Functions.TestFunction" } ;
320
+ yield return new object [ ] { new FunctionInvocationException ( "Invocation failed" , Guid . Empty , "Functions.TestFunction" , new Exception ( "Kaboom" ) ) , "Functions.TestFunction" } ;
321
+ yield return new object [ ] { new FunctionTeapotException ( "Host.Functions.Teapot" , new Exception ( "Super Kaboom" ) ) , "Teapot" } ;
322
+ }
323
+ }
324
+ }
325
+
326
+ private class FunctionTeapotException : FunctionException
327
+ {
328
+ public FunctionTeapotException ( string methodName , Exception innerException )
329
+ : base ( $ "Error 418. The function '{ methodName } ' is a teapot", methodName , innerException )
330
+ {
331
+ }
332
+ }
294
333
}
295
334
}
0 commit comments