5
5
using System . Collections . Generic ;
6
6
using Microsoft . AspNetCore . Http ;
7
7
using Microsoft . Azure . WebJobs . Host ;
8
+ using Microsoft . Azure . WebJobs . Host . Executors . Internal ;
8
9
using Microsoft . Azure . WebJobs . Host . Indexers ;
9
10
using Microsoft . Azure . WebJobs . Host . Listeners ;
10
11
using Microsoft . Azure . WebJobs . Logging ;
@@ -18,20 +19,20 @@ namespace Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics
18
19
{
19
20
public class SystemLogger : ILogger
20
21
{
21
- private readonly IEventGenerator _eventGenerator ;
22
22
private readonly string _categoryName ;
23
23
private readonly string _functionName ;
24
- private readonly bool _isUserFunction ;
25
24
private readonly string _hostInstanceId ;
26
- private readonly IEnvironment _environment ;
25
+ private readonly bool _isUserFunction ;
27
26
private readonly LogLevel _logLevel ;
27
+ private readonly IEnvironment _environment ;
28
+ private readonly IEventGenerator _eventGenerator ;
28
29
private readonly IDebugStateProvider _debugStateProvider ;
29
30
private readonly IScriptEventManager _eventManager ;
30
31
private readonly IExternalScopeProvider _scopeProvider ;
31
32
private AppServiceOptions _appServiceOptions ;
32
33
33
- public SystemLogger ( string hostInstanceId , string categoryName , IEventGenerator eventGenerator , IEnvironment environment ,
34
- IDebugStateProvider debugStateProvider , IScriptEventManager eventManager , IExternalScopeProvider scopeProvider , IOptionsMonitor < AppServiceOptions > appServiceOptionsMonitor )
34
+ public SystemLogger ( string hostInstanceId , string categoryName , IEventGenerator eventGenerator , IEnvironment environment , IDebugStateProvider debugStateProvider ,
35
+ IScriptEventManager eventManager , IExternalScopeProvider scopeProvider , IOptionsMonitor < AppServiceOptions > appServiceOptionsMonitor )
35
36
{
36
37
_environment = environment ;
37
38
_eventGenerator = eventGenerator ;
@@ -59,13 +60,12 @@ public bool IsEnabled(LogLevel logLevel)
59
60
60
61
public void Log < TState > ( LogLevel logLevel , EventId eventId , TState state , Exception exception , Func < TState , Exception , string > formatter )
61
62
{
62
- if ( ! IsEnabled ( logLevel ) || _isUserFunction )
63
+ if ( ! IsEnabled ( logLevel ) || _isUserFunction || FunctionInvoker . CurrentScope == FunctionInvocationScope . User )
63
64
{
64
65
return ;
65
66
}
66
67
67
- // enumerate all the state values once, capturing the values we'll use below
68
- // last one wins
68
+ // Enumerate all the state values once, capturing the values we'll use below - last one wins.
69
69
string stateSourceValue = null ;
70
70
string stateFunctionName = null ;
71
71
string stateEventName = null ;
@@ -110,7 +110,7 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except
110
110
}
111
111
}
112
112
113
- // propagate special exceptions through the EventManager
113
+ // Propagate special exceptions through the EventManager.
114
114
string source = _categoryName ?? stateSourceValue ;
115
115
if ( exception is FunctionIndexingException && _eventManager != null )
116
116
{
@@ -152,9 +152,9 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except
152
152
}
153
153
}
154
154
155
- // Apply standard event properties
155
+ // Apply standard event properties.
156
156
// Note: we must be sure to default any null values to empty string
157
- // otherwise the ETW event will fail to be persisted (silently)
157
+ // otherwise the ETW event will fail to be persisted (silently).
158
158
string summary = formattedMessage ?? string . Empty ;
159
159
string eventName = ! string . IsNullOrEmpty ( eventId . Name ) ? eventId . Name : stateEventName ?? string . Empty ;
160
160
eventName = isDiagnosticEvent ? $ "DiagnosticEvent-{ diagnosticEventErrorCode } " : eventName ;
0 commit comments