Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nlog Date layout need to get the datetime offset with the long date

Tags:

c#

nlog

Tried

${longdate:format=yyyy-MM-ddTHH\\:mm:ss.ffffK} 

but its not writing in offset into the file using Nlog. Tried

${date:format=yyyy-MM-ddTHH\\:mm:ss.ffffK} 

it gives the offset and the time output. Even tried zzz instead of K.

Can we give any other usage for getting the UTC offset in Nlog consoleLayout.Text?

like image 947
Joe Pauly Avatar asked Sep 01 '25 02:09

Joe Pauly


2 Answers

To log DateTimeOffset in database, I use this:

<parameter name="@logged" layout="${longdate}${date:format= K}" />

Please note, that space following = really matters! I checked NLog internal log and here is what I found:

Logged value (with space): 2017-04-21 10:05:48.1868000 +02:00

Logged value (without space): 2017-04-21 10:05:48.1868000

Hope it helped.

like image 163
Dzoukr Avatar answered Sep 02 '25 15:09

Dzoukr


${date:format=yyyy-MM-ddTHH\:mm\:ss.ffff}${date:format=%K}

will get you what you want

like image 36
a113nw Avatar answered Sep 02 '25 15:09

a113nw