Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nlog substring in layout

Tags:

c#

nlog

is there a way to get a substring of the message to the nlog layout? something like ${${substring(0,200)}message}

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

It would be cool if that would write the equlivent of 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> 
like image 937
eiu165 Avatar asked Feb 21 '23 20:02

eiu165


1 Answers

You may use ${pad} layout renderer:

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

Positive padding values cause left padding, negative values cause right padding to the desired width. Documentation

Or try to use T-SQL SUBSTR:

<commandText>
  INSERT INTO [Log] ([Description] ,[Summary] ,[Level] )
  VALUES (@Description,  SUBSTR(@Summary, 1, 200),  @Level)
</commandText>
like image 171
kolbasov Avatar answered Mar 04 '23 18:03

kolbasov