Adding a time-stamp to the default trace logging

gustinn's Avatar

gustinn

28 Sep, 2017 11:35 AM

Hi there,

in this problem discussion you wrote:

[...] unfortunately this behavior is by design. We are going to completely rework PostSharp.Patterns.Diagnostics framework in PostSharp 5.0. [...]

Now, we do have PostSharp 5.0 already.
So, do we have a solution to include time-stamp in logging with the System.Diagnostics.Trace backend?

That would be very helpful in our case.

Thx a lot in advance!

  1. Support Staff 1 Posted by PostSharp Techn... on 01 Oct, 2017 09:42 AM

    PostSharp Technologies's Avatar

    Hello,

    logging is now much more extensible, so you can change the way backend assembles a logging message. See more information about customization here. Probably your only option is to override the TraceLoggingBackend in the following way:

    public class CustomTraceLoggingBackend : TraceLoggingBackend
    {
        public override LogRecordBuilder CreateRecordBuilder()
        {
            return new CustomTraceLogRecordBuilder(this);
        }
    }
    
    public class CustomTraceLogRecordBuilder : TraceLogRecordBuilder
    {
        public CustomTraceLogRecordBuilder(CustomTraceLoggingBackend backend) : base(backend)
        {
        }
    
        protected override void Write(UnsafeString message)
        {
            Trace.Write(DateTime.Now + ": ");
            base.Write(message);
        }
    }
    

    Please let us know if this works for you.

    Best regards,
    Daniel

  2. 2 Posted by gustinn on 04 Oct, 2017 09:12 PM

    gustinn's Avatar

    Hello,

    thank you, that solved my problem!

  3. Support Staff 3 Posted by PostSharp Techn... on 05 Oct, 2017 01:09 PM

    PostSharp Technologies's Avatar

    Hello,

    We are going to close this request as we believe it was solved. Please feel free to reopen the discussion if you need more help.

    Best regards,
    Jakub

  4. PostSharp Technologies closed this discussion on 05 Oct, 2017 01:09 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac