Class TraceUtil
Provides various diagnostic utilities for tracing methods, exception and more.
Inheritance
Namespace: Syncfusion.Diagnostics
Assembly: Syncfusion.Shared.Base.dll
Syntax
public sealed class TraceUtil : Object
Methods
CloseTraceFile()
Declaration
public static void CloseTraceFile()
IsCalledFrom(MethodBase)
Indicates whether a given procedure is being called by another procedure.
Declaration
public static bool IsCalledFrom(MethodBase method)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Reflection.MethodBase | method | The method to be looked up in the stack trace. |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if method was found; false otherwise. |
Examples
if (TraceUtil.IsCalledFrom(typeof(Form1).GetMethod("Form1_Load", BindingFlags.NonPublic|BindingFlags.Instance)))
Debugger.Break();
StartTraceFile(String)
Declaration
public static void StartTraceFile(string fileName)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | fileName |
TraceCalledFrom()
Writes a trace log of the current stack.
Declaration
public static void TraceCalledFrom()
TraceCalledFrom(Int32)
Writes a trace log of the current stack.
Declaration
public static void TraceCalledFrom(int levels)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | levels | The number of method on the stack to trace. |
TraceCalledFromIf(Boolean, Int32, Object[])
Writes a trace log with information about current class and method name and string representations of any method arguments if the condition is true.
Declaration
public static void TraceCalledFromIf(bool condition, int levels, params object[] args)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Boolean | condition | Indicates whether to skip or write the log. |
| System.Int32 | levels | The number of levels to check in call stack. |
| System.Object[] | args | An array of method arguments. |
Examples
The following method shows typical usage of this diagnostic method.
private void OnTimerElapsed(object source, ElapsedEventArgs e)
{
TraceUtil.TraceCalledFromIf(Switches.Timers.TraceVerbose, 3);
}
TraceCurrentMethodInfo(Object[])
Writes a trace log with information about current class and method name and string representations of any method arguments.
Declaration
public static void TraceCurrentMethodInfo(params object[] args)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object[] | args | An array of method arguments. |
TraceCurrentMethodInfoIf(Boolean, Object[])
Writes a trace log with information about current class and method name and string representations of any method arguments if the condition is true.
Declaration
public static void TraceCurrentMethodInfoIf(bool condition, params object[] args)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Boolean | condition | Indicates whether to skip or write the log. |
| System.Object[] | args | An array of method arguments. |
Examples
The following method shows typical usage of this diagnostic method.
private void OnTimerElapsed(object source, ElapsedEventArgs e)
{
TraceUtil.TraceCurrentMethodInfoIf(Switches.Timers.TraceVerbose);
}
TraceExceptionCatched(Exception)
Writes a trace log for the given exception together with information where the exception was caught.
Declaration
public static void TraceExceptionCatched(Exception e)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Exception | e | An Exception. |