Skip to content

Commit 823c62b

Browse files
committed
NLog.Targets.Stackify - Added logLastParameter to skip scanning of all parameters
1 parent ade1b45 commit 823c62b

File tree

1 file changed

+32
-29
lines changed

1 file changed

+32
-29
lines changed

Src/NLog.Targets.Stackify/StackifyTarget.cs

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class StackifyTarget : TargetWithLayout
2929
public bool? logMethodNames { get; set; }
3030
public bool? logAllParams { get; set; }
3131
public bool? logAllProperties { get; set; }
32+
public bool? logLastParameter { get; set; }
3233

3334
private List<string> _GlobalContextKeys = new List<string>();
3435
private List<string> _MappedContextKeys = new List<string>();
@@ -240,45 +241,47 @@ internal LogMsg Translate(LogEventInfo loggingEvent)
240241
msg.Msg = (formattedMessage ?? "").Trim();
241242

242243
object debugObject = null;
243-
Dictionary<string, object> args = new Dictionary<string, object>();
244244

245245
if ((loggingEvent.Parameters != null) && (loggingEvent.Parameters.Length > 0))
246-
{
247-
248-
for (int i = 0; i < loggingEvent.Parameters.Length; i++)
246+
{
247+
Dictionary<string, object> args = (logAllParams ?? true) ? new Dictionary<string, object>() : null;
248+
if (args != null || (logLastParameter ?? true))
249249
{
250-
var item = loggingEvent.Parameters[i];
251-
252-
if (item == null)
250+
for (int i = 0; i < loggingEvent.Parameters.Length; i++)
253251
{
254-
continue;
255-
}
256-
else if (item is Exception)
257-
{
258-
if (loggingEvent.Exception == null)
252+
var item = loggingEvent.Parameters[i];
253+
254+
if (item == null)
259255
{
260-
loggingEvent.Exception = (Exception)item;
256+
continue;
257+
}
258+
else if (item is Exception)
259+
{
260+
if (loggingEvent.Exception == null)
261+
{
262+
loggingEvent.Exception = (Exception)item;
263+
}
264+
}
265+
else if (item.ToString() == msg.Msg)
266+
{
267+
//ignore it.
268+
}
269+
else if (args != null)
270+
{
271+
args["arg" + i] = loggingEvent.Parameters[i];
272+
debugObject = item;
273+
}
274+
else
275+
{
276+
debugObject = item;
261277
}
262278
}
263-
else if (item.ToString() == msg.Msg)
264-
{
265-
//ignore it.
266-
}
267-
else if (logAllParams ?? true)
268-
{
269-
args["arg" + i] = loggingEvent.Parameters[i];
270-
debugObject = item;
271-
}
272-
else
279+
280+
if (args != null && args.Count > 1)
273281
{
274-
debugObject = item;
282+
debugObject = args;
275283
}
276284
}
277-
278-
if ((logAllParams ?? true) && args != null && args.Count > 1)
279-
{
280-
debugObject = args;
281-
}
282285
}
283286

284287

0 commit comments

Comments
 (0)