Replace CR LF in CSV file using replace wrapper

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Replace CR LF in CSV file using replace wrapper


We are using NLog to generate CSV file through CSV layout.

We are logging exception stack trace to CSV. The stack trace contains \r\n and I need to be able to remove this so that each line in the CSV file corresponds to an exception. This will make it very simple to parse the CSV file.

I tried to use ${replace} wrapper layout but the CSV file still contains stack trace in multiple lines.
I have tested that ${replace} wrapper works if I give a different string.

<layout xsi:type="CsvLayout" delimiter="Comma">
            <column name="time" layout="${date:universalTime=true:format=dd-MM-yyyy HH\:mm\:ss ffff }" />
            <column name="level" layout="${level}" />
            <column name="Message" layout="${message}" />
            <column name="StackTrace" layout="${replace:searchFor=\r\n:wholeword=false:replacewith=@:regex=true:inner=${exception:format=StackTrace}}" />

Is there a way to remove the line breaks from stack trace through ${replace} wrapper?