gpt4 book ai didi

c# - MemoryAppender PatternLayout 不渲染?

转载 作者:可可西里 更新时间:2023-11-01 09:00:20 25 4
gpt4 key购买 nike

App.config 看起来像这样:

<appender name="MemoryAppender" type="log4net.Appender.MemoryAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level - %message" />
</layout>
</appender>

代码如下所示:

foreach (var ev in events)
{
string msg = ev.RenderedMessage;
}

ev.RenderedMessage 返回的字符串只是消息,而不是整个模式。我还尝试将 WriteRenderedMessageStringWriter 一起使用,结果是一样的。有没有办法通过应用的模式获取消息?

最佳答案

我找到了:)

var events = _ma.GetEvents();
string result = "";
using (StringWriter writer = new StringWriter())
{
foreach (var ev in events)
{
_ma.Layout.Format(writer, ev);
writer.Write(Environment.NewLine);
}
result = writer.ToString();
}

关于c# - MemoryAppender PatternLayout 不渲染?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14438217/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com