@@ -25,6 +25,7 @@ public class StackifyTarget : TargetWithLayout
2525 public string uri { get ; set ; }
2626 public string globalContextKeys { get ; set ; }
2727 public string mappedContextKeys { get ; set ; }
28+ public string mappedLogicalContextKeys { get ; set ; }
2829 public string callContextKeys { get ; set ; }
2930 public bool ? logMethodNames { get ; set ; }
3031 public bool ? logAllParams { get ; set ; }
@@ -33,6 +34,7 @@ public class StackifyTarget : TargetWithLayout
3334
3435 private List < string > _GlobalContextKeys = new List < string > ( ) ;
3536 private List < string > _MappedContextKeys = new List < string > ( ) ;
37+ private List < string > _MappedLogicalContextKeys = new List < string > ( ) ;
3638 private List < string > _CallContextKeys = new List < string > ( ) ;
3739
3840 private LogClient _logClient = null ;
@@ -66,13 +68,17 @@ protected override void InitializeTarget()
6668 _MappedContextKeys = mappedContextKeys . Split ( ',' ) . Select ( s => s . Trim ( ) ) . ToList ( ) ;
6769 }
6870
71+ if ( ! String . IsNullOrEmpty ( mappedLogicalContextKeys ) )
72+ {
73+ _MappedLogicalContextKeys = mappedLogicalContextKeys . Split ( ',' ) . Select ( s => s . Trim ( ) ) . ToList ( ) ;
74+ }
75+
6976 if ( ! String . IsNullOrEmpty ( callContextKeys ) )
7077 {
7178 _CallContextKeys = callContextKeys . Split ( ',' ) . Select ( s => s . Trim ( ) ) . ToList ( ) ;
7279 }
7380
74-
75- _HasContextKeys = _GlobalContextKeys . Any ( ) || _MappedContextKeys . Any ( ) || _CallContextKeys . Any ( ) ;
81+ _HasContextKeys = _GlobalContextKeys . Any ( ) || _MappedContextKeys . Any ( ) || _MappedLogicalContextKeys . Any ( ) || _CallContextKeys . Any ( ) ;
7682 }
7783
7884 protected override void Write ( LogEventInfo logEvent )
@@ -143,10 +149,10 @@ private Dictionary<string, object> GetDiagnosticContextProperties()
143149 properties . Add ( mdcKey . ToLower ( ) , mdcValue ) ;
144150 }
145151 }
146- }
147-
148- // MappedDiagnosticsLogicalContext (Async CallContext)
149- foreach ( string mdlcKey in _MappedContextKeys )
152+ }
153+
154+ // MappedDiagnosticsLogicalContext (Async CallContext)
155+ foreach ( string mdlcKey in _MappedLogicalContextKeys )
150156 {
151157 if ( NLog . MappedDiagnosticsLogicalContext . Contains ( mdlcKey ) )
152158 {
@@ -242,8 +248,21 @@ internal LogMsg Translate(LogEventInfo loggingEvent)
242248
243249 object debugObject = null ;
244250
245- if ( ( loggingEvent . Parameters != null ) && ( loggingEvent . Parameters . Length > 0 ) )
246- {
251+ if ( ( logAllProperties ?? true ) && loggingEvent . Properties . Count > 0 )
252+ {
253+ Dictionary < string , object > args = new Dictionary < string , object > ( ) ;
254+ foreach ( KeyValuePair < object , object > eventProperty in loggingEvent . Properties )
255+ {
256+ string propertyKey = eventProperty . Key . ToString ( ) ;
257+ if ( ! string . IsNullOrEmpty ( propertyKey ) )
258+ {
259+ args [ propertyKey ] = eventProperty . Value ;
260+ }
261+ }
262+ debugObject = args ;
263+ }
264+ else if ( loggingEvent . Parameters != null && loggingEvent . Parameters . Length > 0 )
265+ {
247266 Dictionary < string , object > args = ( logAllParams ?? true ) ? new Dictionary < string , object > ( ) : null ;
248267 if ( args != null || ( logLastParameter ?? true ) )
249268 {
@@ -284,7 +303,6 @@ internal LogMsg Translate(LogEventInfo loggingEvent)
284303 }
285304 }
286305
287-
288306 StackifyError error = null ;
289307
290308 if ( loggingEvent . Exception != null && loggingEvent . Exception is StackifyError )
@@ -297,22 +315,6 @@ internal LogMsg Translate(LogEventInfo loggingEvent)
297315 }
298316
299317 var diags = GetDiagnosticContextProperties ( ) ;
300-
301- if ( logAllProperties ?? true )
302- {
303- if ( loggingEvent . Properties . Count > 0 )
304- {
305- foreach ( KeyValuePair < object , object > eventProperty in loggingEvent . Properties )
306- {
307- string propertyKey = eventProperty . Key . ToString ( ) ;
308- if ( ! string . IsNullOrEmpty ( propertyKey ) )
309- {
310- diags [ propertyKey . ToLower ( ) ] = eventProperty . Value ;
311- }
312- }
313- }
314- }
315-
316318 if ( diags != null && diags . ContainsKey ( "transid" ) )
317319 {
318320 msg . TransID = diags [ "transid" ] . ToString ( ) ;
0 commit comments