The easiest way to do what you want is to set the Timestamp
property of the LogEntry
.
E.g.:
LogEntry le = new LogEntry()
{
Message = "Log it",
TimeStamp = DateTime.Now // use local time
};
le.Categories.Add("General");
Logger.Write(le);
Other options to do what you want would be to create a Custom Trace Listener or to modify the WriteLog
stored procedure to use any value you wish. You could simply use GETDATE()
or you could do some manipulation of the passed in UTC Timestamp:
DATEADD(HOUR, DATEDIFF(HOUR, GETUTCDATE(), GETDATE()), timestamp)
As a point of interest (since you wouldn't normally use this type of code), if you use the Write() method of the FormattedDatabaseTraceListener
directly it uses the local DateTime. E.g.:
var dbWriter = new FormattedDatabaseTraceListener(
EnterpriseLibraryContainer.Current.GetInstance<Database>(),
"writeLog", "AddCategory", new TextFormatter());
dbWriter.Write("Log this!", "General");
But as a commenter wrote, I would recommend sticking with UTC.