camous
camous

Reputation: 1000

get localtime of DateTime in System.Diagnostics.Trace

I've defined some listeners in my app.config + adding traceOutputOptions with a DateTime. It's totally fit my needs of no extra package (log4net)/no extra config.

But the DateTime in the file are UTC ones which make then often hard to "quick read" & compare. Is there any way to force the output in localtime without overriding the default trace system ?

<trace autoflush="true" indentsize="4">
      <listeners>
        <add name="delimitedListener" type="System.Diagnostics.DelimitedListTraceListener" delimiter=";" initializeData="output.log" traceOutputOptions="DateTime">
            <filter type="System.Diagnostics.EventTypeFilter" initializeData="Warning"/>
        </add>
        <add name="consoleListener" type="System.Diagnostics.ConsoleTraceListener"/>
        <remove name="Default" />
      </listeners>
    </trace>

Upvotes: 2

Views: 1099

Answers (1)

Jon Miller
Jon Miller

Reputation: 51

I'm pretty sure there is no way to make it use local time instead. I think I may have submitted a bug report on this a long time ago and Microsoft said they weren't going to fix it. If I remember correctly, Microsoft said that it would cause performance problems to print it in local time. Also, I think it may have had to do with the fact that the info can be logged to ETW? Seems really stupid to me. I'd be willing to take a performance hit for it as it is very user hostile to have to convert date/times from GMT. I agree with you, I'd rather just use .NET's built in logging than to have to add a dependency to Log4net. Unfortunately, Microsoft seems to not care to make this very robust. It seems like a really obvious usability issue to me.

Upvotes: 2

Related Questions