The following is in config file.
<formatters>
<add template="{timestamp} {severity} {category} {message}" type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="SingleLineFormatter" />
</formatters>
which displays
31/05/2011 11:43:24 Information ...
But there is no millisecond displayed which would be useful for perf instrumentation, anyone knows how to display? Thanks.
You can specify Standard or Custom DateTime
Format strings to the timestamp template token:
<formatters>
<add
template="{timestamp(MM/dd/yyyy HH:mm:ss.fffffff)} {severity} {category} {message}"
type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="SingleLineFormatter" />
</formatters>
This would output something like:
06/01/2011 20:12:43.3405776 Information General This is the message
By default the DateTime will be in UTC time. If you wish to use local time then prefix the format string with "local:". e.g. {timestamp(local:MM/dd/yyyy HH:mm:ss.fffffff)}
Also, if you are looking to log performance tracing of method entries and exits you may want to look at the Tracer
class.
Unfortunately, Enterprise library logging uses the .net DateTime so although logging milliseconds is possible as descriped by @Tuzo, it is at best meaningless and at worst misleading.
Eric Lippert wrote an interesting explanation of this: https://stackoverflow.com/a/2143784/230428
The precision of any value will be at best plus or minus 50ms (although this varies form machine to machine - another reason for not relying on this). This is beacuse the date time was designed for answering the question "What Date and Time is it?" rather than the question "How long did that take?". For the latter, use the Stopwatch class.
Obviously, the convenience of having a logging framework to beaver away and record your timings can sound tempting, but you shouldn't rely on it for anything less than second-precision timings.
I first came accross this when my MVC OnActionExecuting and OnActionExecuted logs were returning the very same time to the microsecond. Very impressive and equally wrong.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With