Loupe - Log - Monitor - Resolve
Gibraltar.Agent.PostSharp Namespace / GTrace Class
Members Example

In This Topic
    GTrace Class
    In This Topic
    A PostSharp aspect used to trace entry and successful exit from methods. It also measures method execution time.

    Enables the logging of method entry and exit at runtime complete with parameter information and results.

    Public NotInheritable Class GTrace 
       Inherits GAspectBase
       Implements Gibraltar.Agent.IMessageSourceProvider, PostSharp.Aspects.IAspect, PostSharp.Aspects.IAspectBuildSemantics, PostSharp.Aspects.IMethodLevelAspect, PostSharp.Aspects.IMethodLevelAspectBuildSemantics, PostSharp.Aspects.IOnMethodBoundaryAspect, PostSharp.Extensibility.IValidableAnnotation 
    public sealed class GTrace : GAspectBase, Gibraltar.Agent.IMessageSourceProvider, PostSharp.Aspects.IAspect, PostSharp.Aspects.IAspectBuildSemantics, PostSharp.Aspects.IMethodLevelAspect, PostSharp.Aspects.IMethodLevelAspectBuildSemantics, PostSharp.Aspects.IOnMethodBoundaryAspect, PostSharp.Extensibility.IValidableAnnotation  

    GTrace is a PostSharp aspect used to trace entry and exit from methods. It writes a message to the log every time an associated method is entered and when it returns. Additionally:

    • The input parameters to the method are recorded for the entering message
    • The execution time of the method is recorded in the exiting message.
    • The return value (if any) is recorded in the exiting message
    • If the method is exiting because an exception is being thrown out of the method that is noted and the exception details are recorded.
    • The log messages are attributed to the source code location that invoked the method, if source code location information is available.

    Log Message Categorization

    Each log message is recorded in an automatically generated category in the form {BaseCategory}.Trace.Enter or {BaseCategory}.Trace.Exit. See the BaseCategory property for more information on changing the log message category.

    Enabling and Disabling at Runtime

    Because GTrace messages are voluminous and detailed it's often useful to enable and disable them at runtime. To do this just set the Enabled property which will affect all methods instrumented with GTrace in the current process. When disabled GTrace has minimal performance impact even in high volume scenarios.

    Refining Data Captured

    You can turn down the amount of information captured for a given method by GTrace by setting the LogParameters, LogReturnValue, and EnableSourceLookup properties. These are particularly handy if you know that the parameter information is very large and not generally interesting.

    You can associate the GTrace attribute with a single method, a property, or an entire class to trace all methods in that class. You can also use attribute multicasting to apply it to all matching methods in your assembly.
    Trace one method within a class
    public class SampleApplication
        private void InterestingMethod(int valueOne, String anotherValue)
            //Do something interesting here
    Trace all methods within a class
    public class SampleApplication
        private void InterestingMethod(int valueOne, String anotherValue)
            //Do something interesting here
        private void AnotherInterestingMethod(int valueTwo, String anotherValue)
            //Do something even more interesting here
    Inheritance Hierarchy



    Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

    See Also