SamehMohamedEl-Sayed / elmah

Automatically exported from code.google.com/p/elmah
Apache License 2.0
0 stars 0 forks source link

XmlFileErrorLog: filename timestamp does not match actual time of error #156

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
When an Error object is created (Error.cs constructor), it stores the time
in its _time field.
However, when XmlFileErrorLog (XmlFileErrorLog.cs) actually logs that
error, it makes another call to DateTime object and converts it to string
in order to use in the filename as a time-stamp.

This behavior sometimes causes the seconds fraction in the filename to be
different that the one in the error object's time property, due to time
difference between the two calls (the one in the Error's constructor, and
the one in the XmlFileErrorLog's Log method).

In XmlFileErrorLog's Log method, using the error's time property to create
a time-stamp should fix the issue. Like so ;

Instead of : var timeStamp = DateTime.UtcNow.ToString("yyyy-MM-ddHHmmssZ",
CultureInfo.InvariantCulture);
This would be better : var timeStamp =
error.Time.ToUniversalTime().ToString("yyyy-MM-ddHHmmssZ",
CultureInfo.InvariantCulture);

Original issue reported on code.google.com by cagdaste...@gmail.com on 19 Feb 2010 at 4:24

GoogleCodeExporter commented 9 years ago

Original comment by azizatif on 19 Feb 2010 at 5:42

GoogleCodeExporter commented 9 years ago

Original comment by azizatif on 19 Feb 2010 at 6:39

GoogleCodeExporter commented 9 years ago
Fixed in r709.

Original comment by azizatif on 20 Feb 2010 at 8:24

GoogleCodeExporter commented 9 years ago
Demonstration of fix:

IronPython 2.6 (2.6.10920.0) on .NET 2.0.50727.4200
Type "help", "copyright", "credits" or "license" for more information.
>>> import clr
>>> clr.AddReference('Elmah')
>>> from System import DateTime, ApplicationException
>>> from System.IO import Directory
>>> from Elmah import Error, XmlFileErrorLog
>>> log = XmlFileErrorLog(r'C:\errors')
>>> error = Error(ApplicationException())
>>> error.Time = DateTime(2010, 1, 1, 12, 0, 0)
>>> log.Log(error)
'93061650-58ff-4d7d-91de-ca97e555db8c'
>>> print '\n'.join(Directory.GetFiles(log.LogPath))
C:\errors\error-2010-01-01110000Z-93061650-58ff-4d7d-91de-ca97e555db8c.xml

The time embedded in the file is that which was set on the Error object's Time 
property.

Original comment by azizatif on 20 Feb 2010 at 8:30