@@ -22,21 +22,24 @@ public class SystemLogger : ILogger
22
22
private readonly LogLevel _logLevel ;
23
23
private readonly IDebugStateProvider _debugStateProvider ;
24
24
private readonly IScriptEventManager _eventManager ;
25
+ private readonly IExternalScopeProvider _scopeProvider ;
25
26
26
- public SystemLogger ( string hostInstanceId , string categoryName , IEventGenerator eventGenerator , IEnvironment environment , IDebugStateProvider debugStateProvider , IScriptEventManager eventManager )
27
+ public SystemLogger ( string hostInstanceId , string categoryName , IEventGenerator eventGenerator , IEnvironment environment ,
28
+ IDebugStateProvider debugStateProvider , IScriptEventManager eventManager , IExternalScopeProvider scopeProvider )
27
29
{
28
30
_environment = environment ;
29
31
_eventGenerator = eventGenerator ;
30
32
_categoryName = categoryName ?? string . Empty ;
31
33
_logLevel = LogLevel . Debug ;
32
- _functionName = LogCategories . IsFunctionCategory ( _categoryName ) ? _categoryName . Split ( '.' ) [ 1 ] : string . Empty ;
34
+ _functionName = LogCategories . IsFunctionCategory ( _categoryName ) ? _categoryName . Split ( '.' ) [ 1 ] : null ;
33
35
_isUserFunction = LogCategories . IsFunctionUserCategory ( _categoryName ) ;
34
36
_hostInstanceId = hostInstanceId ;
35
37
_debugStateProvider = debugStateProvider ;
36
38
_eventManager = eventManager ;
39
+ _scopeProvider = scopeProvider ;
37
40
}
38
41
39
- public IDisposable BeginScope < TState > ( TState state ) => DictionaryLoggerScope . Push ( state ) ;
42
+ public IDisposable BeginScope < TState > ( TState state ) => _scopeProvider . Push ( state ) ;
40
43
41
44
public bool IsEnabled ( LogLevel logLevel )
42
45
{
@@ -63,7 +66,9 @@ private bool IsUserLog<TState>(TState state)
63
66
public void Log < TState > ( LogLevel logLevel , EventId eventId , TState state , Exception exception , Func < TState , Exception , string > formatter )
64
67
{
65
68
// propagate special exceptions through the EventManager
66
- string source = _categoryName ?? Utility . GetValueFromState ( state , ScriptConstants . LogPropertySourceKey ) ;
69
+ var stateProps = state as IEnumerable < KeyValuePair < string , object > > ?? new Dictionary < string , object > ( ) ;
70
+
71
+ string source = _categoryName ?? Utility . GetStateValueOrDefault < string > ( stateProps , ScriptConstants . LogPropertySourceKey ) ;
67
72
if ( exception is FunctionIndexingException && _eventManager != null )
68
73
{
69
74
_eventManager . Publish ( new FunctionIndexingEvent ( "FunctionIndexingException" , source , exception ) ) ;
@@ -83,7 +88,7 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except
83
88
return ;
84
89
}
85
90
86
- IDictionary < string , object > scopeProps = DictionaryLoggerScope . GetMergedStateDictionary ( ) ?? new Dictionary < string , object > ( ) ;
91
+ IDictionary < string , object > scopeProps = _scopeProvider . GetScopeDictionary ( ) ;
87
92
88
93
// Apply standard event properties
89
94
// Note: we must be sure to default any null values to empty string
@@ -93,11 +98,11 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except
93
98
string summary = Sanitizer . Sanitize ( formattedMessage ) ?? string . Empty ;
94
99
string innerExceptionType = string . Empty ;
95
100
string innerExceptionMessage = string . Empty ;
96
- string functionName = _functionName ;
97
- string eventName = ! string . IsNullOrEmpty ( eventId . Name ) ? eventId . Name : Utility . GetValueFromState ( state , ScriptConstants . LogPropertyEventNameKey ) ;
101
+ string functionName = _functionName ?? Utility . ResolveFunctionName ( stateProps , scopeProps ) ?? string . Empty ;
102
+ string eventName = ! string . IsNullOrEmpty ( eventId . Name ) ? eventId . Name : Utility . GetStateValueOrDefault < string > ( stateProps , ScriptConstants . LogPropertyEventNameKey ) ?? string . Empty ;
98
103
string functionInvocationId = Utility . GetValueFromScope ( scopeProps , ScriptConstants . LogPropertyFunctionInvocationIdKey ) ?? string . Empty ;
99
104
string hostInstanceId = _hostInstanceId ;
100
- string activityId = Utility . GetValueFromState ( state , ScriptConstants . LogPropertyActivityIdKey ) ;
105
+ string activityId = Utility . GetStateValueOrDefault < string > ( stateProps , ScriptConstants . LogPropertyActivityIdKey ) ?? string . Empty ;
101
106
string runtimeSiteName = _environment . GetRuntimeSiteName ( ) ?? string . Empty ;
102
107
103
108
// Populate details from the exception.
0 commit comments