gpt4 book ai didi

c# - 布局中的 nlog 子串

转载 作者:行者123 更新时间:2023-11-30 14:37:49 36 4
gpt4 key购买 nike

有没有办法将消息的子字符串添加到 nlog 布局?类似于${${substring(0,200)}message}

        <parameter name="@Summary" layout="${substring(0,200)}${message}"/>

如果这样写出 message.substring(0, 200) 的 equlivent 就好了

    <target type="Database" name="databaseLog" 
ConnectionStringName="ApplicationConnectionString">
<commandText>
INSERT INTO [Log] ([Description] ,[Summary] ,[Level] )
VALUES (@Description, @Summary, @Level )
</commandText>

<parameter name="@Description" layout="${message}"/>
<parameter name="@Summary" layout="{{SUBSTRING-OF-MESSAGE-HERE}}"/>
<parameter name="@Level" layout="${level}"/>
</target>

最佳答案

您可以使用 ${pad} 布局渲染器:

layout=${pad:padding=-200:fixedLength=true:inner=${message}}

正填充值导致左侧填充,负值导致右侧填充到所需宽度。 Documentation

或者尝试使用 T-SQL SUBSTR:

<commandText>
INSERT INTO [Log] ([Description] ,[Summary] ,[Level] )
VALUES (@Description, SUBSTR(@Summary, 1, 200), @Level)
</commandText>

关于c# - 布局中的 nlog 子串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8856490/

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