Turn on / off message tracking in runtime?

Can someone tell me if in PostSharp I can somehow enable / disable tracking at runtime? I need to write less code, so lately I could just delete it. The trace function is temporarily required.

Maybe there is an alternative to PostSharp with on / off function at runtime?

Update 1: I got an idea, but I don't know if this is good. Here is an example

public class Smth { private long i = 0; [TraceAttribute] public void Execute() { Console.WriteLine("Execute call" + i++); Thread.Sleep(200); } } [Serializable] public class TraceAttribute : OnMethodBoundaryAspect { public override void OnEntry(MethodExecutionArgs args) { if(Manager.IsEnabled) { Console.WriteLine(); Console.WriteLine(string.Format("Entering {0}", args.Method.Name)); } } public override void OnExit(MethodExecutionArgs args) { if(Manager.IsEnabled) { Console.WriteLine(string.Format("Leaving {0}", args.Method.Name)); Console.WriteLine(); } } } public static class Manager { public static bool IsEnabled { get; set; } static Manager() { IsEnabled = true; } } 

By changing the IsEnabled property, I was able to enable / disable tracking ... Any other suggestions?

+4
source share
1 answer

Everything is fine with you (as long as it is temporary). Easily apply an aspect using multicast. See My Articles http://www.sharpcrafters.com/blog/post/Day-2-Applying-Aspects-with-Multicasting-Part-1.aspx and http://www.sharpcrafters.com/blog/post/ Day-3-Applying-Aspects-with-Multicasting-Part-2.aspx

Disclaimer: I assume that the OP wants to do this without recovery, as he said that he is convincing that he wants to install the configuration. Otherwise, I would suggest a much different route

+1
source

All Articles