除了创建自己的LayoutRenderer之外,我看不到任何明显的方法(见下文).如果您正在进行自己的程序集,请不要忘记将以下内容添加到NLog.Config中:
希望这有助于其他人:
[LayoutRenderer("aspnet-config")]
public class AspNetConfigValueLayoutRenderer : LayoutRenderer
{
[DefaultParameter]
public string Variable
{
get;
set;
}
protected override void Append(StringBuilder builder,LogEventInfo logEvent)
{
if (this.Variable == null)
{
return;
}
HttpContext context = HttpContext.Current;
if (context == null)
{
return;
}
builder.Append(Convert.ToString(System.Configuration.ConfigurationManager.AppSettings[this.Variable],CultureInfo.InvariantCulture));
}
}