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?
GaaRa source share