Skip to content

Log records come out in UTC not in local time zone #7

@SuperSkippy

Description

@SuperSkippy

I am finding that when I use webapi.nlog that all the trace records come out with timestamps in UTC not the local time zone. Is this intended?

If I use the standard logger.Trace, logger.Error methods in NLog they all come out with localtime (and are made with localtime timestamps).

I have "fixed" it in my copy by changing the CreateEvent method in NLogTraceWriter to read:

private LogEventInfo CreateEvent(TraceRecord record, LogLevel logLevel)
{
// create new log event info based off TraceRecord properties specified by app
var logEvent = new LogEventInfo
{
Level = logLevel,
Message = record.Message,
LoggerName = record.Category,
Exception = record.Exception,
TimeStamp = record.Timestamp.ToLocalTime()
};

        // load properties on the log event, this will be used downstream by the layout renderers
        PopulateProperties(record, logEvent);

        return logEvent;
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions