RequestLogsFeature local time

Is it possible to change the DateTime used in the RequestLogsFeature to local instead of UTC?
This means that DateTime fields in the log entries will be displayed as local date strings, and the logging will start fresh at midnight local time instead of UTC time.

This would help with readability when glancing at raw logs exposed via the AtRestPath endpoint. The UTC dates make it a little annoying to interpret at a glance.

We specifically use UTC for most Dates in order to generate predictable consistent dates across different servers in multiple time zones. I’ve added a filter you can use to customize the RequestLogEntry in this commit so you can customize the LogEntry with:

Plugins.Add(new RequestLogsFeature { 
    RequestLogFilter = (req,entry) => entry.DateTime = DateTime.Now
});

This change is available from v5.4.1 that’s now available on MyGet.

That’s understandable, thank you for adding the filter though. :smiley:
Will this move new log creation to midnight of the specified date too, or is that something else?

Are you talking about CSV Request Logger? As that uses something else in:

You’d need a custom CsvRequestLogger that overrides OnFlush() with your own custom impl.

Decided to add a specific CurrentDateFn option to change what to use for the Current Date in all Request Logger providers, so now you can change to use Local Time with:

Plugins.Add(new RequestLogsFeature { 
    CurrentDateFn = () => DateTime.Now
});

This change is now available on MyGet, if you had v5.4.1 installed you’ll need to clear your NuGet cache.

1 Like

That’s great, thank you. :smiley:
I’ll give it a try soon…

Hm, I’m getting a startup crash. I don’t even set CurrentDateFn and it happens. Does it work on your end?

This suggests you have dirty .dll’s where you still have an old ServiceStack.dll. Make sure you clear your NuGet packages cache so you’re using the latest version, e.g:

$ nuget locals all -clear

That doesn’t appear to be the issue. I’ve verified the deployed dlls on the server are v5.4.1 from 2 days ago.
Just in case, I deleted the whole packages folder from my project, restored, and get the same dlls.

The pre-release packages have the same version number so you could have an old v5.4.1 .dll’s mixed with the newer version that has the CurrentDateFn which is the only way you can get this error since the .dll that has this feature has this method.

Make sure you’re running this on the command line with a recent NuGet.exe to clear your local NuGet packages cache

$ nuget locals all -clear

I ran that command, caches cleared successfully, still getting the crash.
I created a new project that reproduces the crash. Run it with the latest MyGet packages restored and you should see this:

ok I’ve re-run all CI projects and published to MyGet again. Your project runs without issue so if you clear your NuGet cache again, you should no longer have this issue.

Yup, now it works. :+1: