55using System . Collections . Generic ;
66using Microsoft . AspNetCore . Http ;
77using Microsoft . Azure . WebJobs . Host ;
8+ using Microsoft . Azure . WebJobs . Host . Executors . Internal ;
89using Microsoft . Azure . WebJobs . Host . Indexers ;
910using Microsoft . Azure . WebJobs . Host . Listeners ;
1011using Microsoft . Azure . WebJobs . Logging ;
@@ -18,20 +19,20 @@ namespace Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics
1819{
1920 public class SystemLogger : ILogger
2021 {
21- private readonly IEventGenerator _eventGenerator ;
2222 private readonly string _categoryName ;
2323 private readonly string _functionName ;
24- private readonly bool _isUserFunction ;
2524 private readonly string _hostInstanceId ;
26- private readonly IEnvironment _environment ;
25+ private readonly bool _isUserFunction ;
2726 private readonly LogLevel _logLevel ;
27+ private readonly IEnvironment _environment ;
28+ private readonly IEventGenerator _eventGenerator ;
2829 private readonly IDebugStateProvider _debugStateProvider ;
2930 private readonly IScriptEventManager _eventManager ;
3031 private readonly IExternalScopeProvider _scopeProvider ;
3132 private AppServiceOptions _appServiceOptions ;
3233
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 )
3536 {
3637 _environment = environment ;
3738 _eventGenerator = eventGenerator ;
@@ -59,13 +60,12 @@ public bool IsEnabled(LogLevel logLevel)
5960
6061 public void Log < TState > ( LogLevel logLevel , EventId eventId , TState state , Exception exception , Func < TState , Exception , string > formatter )
6162 {
62- if ( ! IsEnabled ( logLevel ) || _isUserFunction )
63+ if ( ! IsEnabled ( logLevel ) || _isUserFunction || FunctionInvoker . CurrentScope == FunctionInvocationScope . User )
6364 {
6465 return ;
6566 }
6667
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.
6969 string stateSourceValue = null ;
7070 string stateFunctionName = null ;
7171 string stateEventName = null ;
@@ -110,7 +110,7 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except
110110 }
111111 }
112112
113- // propagate special exceptions through the EventManager
113+ // Propagate special exceptions through the EventManager.
114114 string source = _categoryName ?? stateSourceValue ;
115115 if ( exception is FunctionIndexingException && _eventManager != null )
116116 {
@@ -152,9 +152,9 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except
152152 }
153153 }
154154
155- // Apply standard event properties
155+ // Apply standard event properties.
156156 // 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).
158158 string summary = formattedMessage ?? string . Empty ;
159159 string eventName = ! string . IsNullOrEmpty ( eventId . Name ) ? eventId . Name : stateEventName ?? string . Empty ;
160160 eventName = isDiagnosticEvent ? $ "DiagnosticEvent-{ diagnosticEventErrorCode } " : eventName ;
0 commit comments