本文整理汇总了C#中NLog.Layouts.SimpleLayout.SetRenderers方法的典型用法代码示例。如果您正苦于以下问题:C# SimpleLayout.SetRenderers方法的具体用法?C# SimpleLayout.SetRenderers怎么用?C# SimpleLayout.SetRenderers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NLog.Layouts.SimpleLayout
的用法示例。
在下文中一共展示了SimpleLayout.SetRenderers方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseLayoutRenderer
private static LayoutRenderer ParseLayoutRenderer(ConfigurationItemFactory configurationItemFactory, SimpleStringReader sr)
{
int ch = sr.Read();
Debug.Assert(ch == '{', "'{' expected in layout specification");
string name = ParseLayoutRendererName(sr);
LayoutRenderer lr = configurationItemFactory.LayoutRenderers.CreateInstance(name);
var wrappers = new Dictionary<Type, LayoutRenderer>();
var orderedWrappers = new List<LayoutRenderer>();
ch = sr.Read();
while (ch != -1 && ch != '}')
{
string parameterName = ParseParameterName(sr).Trim();
if (sr.Peek() == '=')
{
sr.Read(); // skip the '='
PropertyInfo pi;
LayoutRenderer parameterTarget = lr;
if (!PropertyHelper.TryGetPropertyInfo(lr, parameterName, out pi))
{
Type wrapperType;
if (configurationItemFactory.AmbientProperties.TryGetDefinition(parameterName, out wrapperType))
{
LayoutRenderer wrapperRenderer;
if (!wrappers.TryGetValue(wrapperType, out wrapperRenderer))
{
wrapperRenderer = configurationItemFactory.AmbientProperties.CreateInstance(parameterName);
wrappers[wrapperType] = wrapperRenderer;
orderedWrappers.Add(wrapperRenderer);
}
if (!PropertyHelper.TryGetPropertyInfo(wrapperRenderer, parameterName, out pi))
{
pi = null;
}
else
{
parameterTarget = wrapperRenderer;
}
}
}
if (pi == null)
{
ParseParameterValue(sr);
}
else
{
if (typeof(Layout).IsAssignableFrom(pi.PropertyType))
{
var nestedLayout = new SimpleLayout();
string txt;
LayoutRenderer[] renderers = CompileLayout(configurationItemFactory, sr, true, out txt);
nestedLayout.SetRenderers(renderers, txt);
pi.SetValue(parameterTarget, nestedLayout, null);
}
else if (typeof(ConditionExpression).IsAssignableFrom(pi.PropertyType))
{
var conditionExpression = ConditionParser.ParseExpression(sr, configurationItemFactory);
pi.SetValue(parameterTarget, conditionExpression, null);
}
else
{
string value = ParseParameterValue(sr);
PropertyHelper.SetPropertyFromString(parameterTarget, parameterName, value, configurationItemFactory);
}
}
}
else
{
// what we've just read is not a parameterName, but a value
// assign it to a default property (denoted by empty string)
PropertyInfo pi;
if (PropertyHelper.TryGetPropertyInfo(lr, string.Empty, out pi))
{
if (typeof(SimpleLayout) == pi.PropertyType)
{
pi.SetValue(lr, new SimpleLayout(parameterName), null);
}
else
{
string value = parameterName;
PropertyHelper.SetPropertyFromString(lr, pi.Name, value, configurationItemFactory);
}
}
else
{
InternalLogger.Warn("{0} has no default property", lr.GetType().FullName);
}
}
ch = sr.Read();
}
//.........这里部分代码省略.........