© 2026 Hedgehog Software, LLC
StackTrace
System.Exception
public void LogException(ex)
public static void LogException( Exception ex ) { Log( $"Exception: {ex.GetType().Name} - {ex.Message}" ); Log( $"Stack trace: {ex.StackTrace}" ); StackTrace stackTrace = new StackTrace( ex, true ); for ( int i = 0; i < stackTrace.FrameCount; i++ ) { StackFrame frame = stackTrace.GetFrame( i ); MethodBase method = frame.GetMethod(); Type declaringType = method.DeclaringType; Log( $"Local variables at frame {i}:" ); MethodInfo methodInfo = method as MethodInfo; if ( methodInfo != null ) { LocalVariableInfo[] localVariables = methodInfo.GetMethodBody()?.LocalVariables?.ToArray(); if ( localVariables != null ) { foreach ( LocalVariableInfo localVariable in localVariables ) { object value = frame.GetMethod().GetMethodBody()?.LocalVariables[localVariable.LocalIndex]; Log( $"{localVariable.LocalType} {localVariable} = {value}" ); } } } Log( $"Method: {declaringType?.FullName}.{method.Name}" ); Log( $"File: {frame.GetFileName()}" ); Log( $"Line: {frame.GetFileLineNumber()}" ); } ExceptionLogged.Invoke( ex ); // Raise the ExceptionLogged event }