Question

What is log4net.Layout.PatternLayout value to output DateTimeOffset data type to database?

This is what I have currently in configuration file for log4net:

<log4net>
....
<parameter>
      <parameterName value="@log_date" />
      <dbType value="DateTime" />
      <layout type="log4net.Layout.PatternLayout" value="%date{yyyy'-'MM'-'dd HH':'mm':'ss'.'fff}" />
</parameter>
...
</log4net>

And I want to have something like:

<log4net>
....
<parameter>
      <parameterName value="@log_date" />
      <dbType value="DateTimeOffset" />
      <layout type="log4net.Layout.PatternLayout" value="%date{yyyy'-'MM'-'dd HH':'mm':'ss'.'fff **OFFSET**}" />
</parameter>
...
</log4net>

Basically we reuse the same DB to log events from clients located in different time zones - so we want to know an exact local time of the event.

Thanks, Alex

Was it helpful?

Solution

You should be able to use any valid DateTime format string. Try this:

%date{yyyy-MM-ddTHH:mm:ss.fffzzz}

OTHER TIPS

Would defining your DB column as DateTime and using %utcdate instead of %date help? That should make all of the timestamps compatible.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top