Skip to content

Commit

Permalink
LayoutParser - Improve output to InternalLogger when setting property…
Browse files Browse the repository at this point in the history
…-values
  • Loading branch information
snakefoot committed Nov 28, 2022
1 parent 084d03a commit 3101e53
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
10 changes: 5 additions & 5 deletions src/NLog/Config/LoggingConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private Target RemoveTargetThreadSafe(string name)

if (target != null)
{
InternalLogger.Debug("Unregistered target {0}(Name={1})", target.GetType().Name, target.Name);
InternalLogger.Debug("Unregistered target {0}(Name={1})", target.GetType(), target.Name);
}

return target;
Expand Down Expand Up @@ -160,11 +160,11 @@ private void AddTargetThreadSafe(Target target, string targetAlias = null)

if (!string.IsNullOrEmpty(target.Name) && !string.Equals(target.Name, targetAlias, StringComparison.OrdinalIgnoreCase))
{
InternalLogger.Info("Registered target {0}(Name={1}) (Extra alias={2})", target.GetType().Name, target.Name, targetAlias);
InternalLogger.Info("Registered target {0}(Name={1}) (Extra alias={2})", target.GetType(), target.Name, targetAlias);
}
else
{
InternalLogger.Info("Registered target {0}(Name={1})", target.GetType().Name, target.Name);
InternalLogger.Info("Registered target {0}(Name={1})", target.GetType(), target.Name);
}
}

Expand Down Expand Up @@ -216,7 +216,7 @@ public void AddTarget([NotNull] Target target)
{
if (target is null) { throw new ArgumentNullException(nameof(target)); }

InternalLogger.Debug("Adding target {0}(Name={1})", target.GetType().Name, target.Name);
InternalLogger.Debug("Adding target {0}(Name={1})", target.GetType(), target.Name);

if (string.IsNullOrEmpty(target.Name)) { throw new ArgumentException(nameof(target) + ".Name cannot be empty", nameof(target)); }

Expand All @@ -235,7 +235,7 @@ public void AddTarget(string name, [NotNull] Target target)
if (name is null) { throw new ArgumentNullException(nameof(name)); }
if (target is null) { throw new ArgumentNullException(nameof(target)); }

InternalLogger.Debug("Adding target {0}(Name={1})", target.GetType().Name, string.IsNullOrEmpty(name) ? target.Name : name);
InternalLogger.Debug("Adding target {0}(Name={1})", target.GetType(), string.IsNullOrEmpty(name) ? target.Name : name);

if (string.IsNullOrEmpty(name)) { throw new ArgumentException("Target name cannot be empty", nameof(name)); }

Expand Down
2 changes: 1 addition & 1 deletion src/NLog/Config/LoggingConfigurationParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1348,7 +1348,7 @@ private Target WrapWithDefaultWrapper(Target target, ValidatedConfigurationEleme
target.Name = target.Name + "_wrapped";

InternalLogger.Debug("Wrapping target '{0}' with '{1}' and renaming to '{2}", wrapperTargetInstance.Name,
wrapperTargetInstance.GetType().Name, target.Name);
wrapperTargetInstance.GetType(), target.Name);
return wrapperTargetInstance;
}

Expand Down
5 changes: 2 additions & 3 deletions src/NLog/Internal/Reflection/PropertyHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,11 @@ namespace NLog.Internal
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Text;
using NLog.Common;
using NLog.Conditions;
using NLog.Config;
using NLog.Internal;
using NLog.Layouts;
using NLog.Targets;

Expand Down Expand Up @@ -92,7 +90,6 @@ internal static class PropertyHelper
internal static void SetPropertyFromString(object targetObject, string propertyName, string stringValue, ConfigurationItemFactory configurationItemFactory)
{
var objType = targetObject.GetType();
InternalLogger.Debug("Setting '{0}.{1}' to '{2}'", objType, propertyName, stringValue);

if (!TryGetPropertyInfo(objType, propertyName, out var propInfo))
{
Expand All @@ -106,6 +103,8 @@ internal static void SetPropertyFromString(object targetObject, PropertyInfo pro
{
object propertyValue = null;

InternalLogger.Debug("Setting '{0}.{1}' to '{2}'", targetObject?.GetType(), propInfo.Name, stringValue);

try
{
var propertyType = Nullable.GetUnderlyingType(propInfo.PropertyType) ?? propInfo.PropertyType;
Expand Down
2 changes: 1 addition & 1 deletion src/NLog/Layouts/LayoutParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ private static string SetDefaultPropertyValue(string value, LayoutRenderer layou
value = EscapeUnicodeStringValue(value);
}

PropertyHelper.SetPropertyFromString(layoutRenderer, propertyInfo.Name, value, configurationItemFactory);
PropertyHelper.SetPropertyFromString(layoutRenderer, propertyInfo, value, configurationItemFactory);
return propertyInfo.Name;
}
else
Expand Down

0 comments on commit 3101e53

Please sign in to comment.