有没有办法将消息的子字符串获取到 nlog 布局?就像是${${substring(0,200)}message}
<parameter name="@Summary" layout="${substring(0,200)}${message}"/>
Run Code Online (Sandbox Code Playgroud)
如果这能写出 message.substring(0, 200); 的等价物,那就太酷了。
<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>
Run Code Online (Sandbox Code Playgroud)
您可以使用 ${pad} 布局渲染器:
layout=${pad:padding=-200:fixedLength=true:inner=${message}}
Run Code Online (Sandbox Code Playgroud)
正填充值导致左填充,负值导致右填充到所需宽度。文档
或者尝试使用 T-SQL SUBSTR:
<commandText>
INSERT INTO [Log] ([Description] ,[Summary] ,[Level] )
VALUES (@Description, SUBSTR(@Summary, 1, 200), @Level)
</commandText>
Run Code Online (Sandbox Code Playgroud)