|
| 1 | +# Desharp - C# & VB .NET Debugging Tool |
| 2 | + |
| 3 | +--- |
| 4 | + |
| 5 | +## What You Can Dump Or Log |
| 6 | + |
| 7 | +- any variables |
| 8 | + - primitive variables and it's primitive arrays like: `char`, `int?[]` and more |
| 9 | + - collections: `Lists`, `Dictionaries` or any collections (`IList`, `IDictionary`, `ICollection`, `IEnumerable`...) |
| 10 | + - database results: `DataSet`, `DataTable` and `DataRow` with values |
| 11 | + - formated instances: `DateTimeOffset`, `DateTime`, `TimeSpan`, `Guid`, `StringBuilder` |
| 12 | + - any custom class instances with rendered events targets, properties values and fields values |
| 13 | + - anonymous objects like: `new { any = "value" }` |
| 14 | + - `Func<>` and `Delegate` types |
| 15 | + - reflection objects are only displayed as type names |
| 16 | +- exceptions |
| 17 | +- exceptions with inner exceptions |
| 18 | +- much more... you can try:-) |
| 19 | + |
| 20 | +--- |
| 21 | + |
| 22 | +## Demos & Examples |
| 23 | + |
| 24 | +- [**Console Application Demo (C#)**](https://github.com/debug-sharp/example-console-csharp), [**(VB.NET)**](https://github.com/debug-sharp/example-console-visualbasic) |
| 25 | + Demo dumps and exceptions rendering into console window, logging on HDD and optional tests running. |
| 26 | +- [**Windows Forms Application Demo (C#)**](https://github.com/debug-sharp/example-win-forms) |
| 27 | + Demo dumps and exceptions rendering into text field component, into debug output window and logging on HDD. |
| 28 | +- [**Web Basic Application Demo (C#)**](https://github.com/debug-sharp/example-web-basic) |
| 29 | + Demo dumps and exceptions rendering into floating browser bar and logging on HDD. |
| 30 | +- [**Web MVC Application Demo (C#)**](https://github.com/debug-sharp/example-web-mvc) |
| 31 | + Demo dumps and exceptions rendering into floating browser bar and logging on HDD. |
| 32 | +- [**Web Forms Application Demo (C#)**](https://github.com/debug-sharp/example-web-forms) |
| 33 | + Demo dumps and exceptions rendering into floating browser bar and logging on HDD. |
| 34 | + |
| 35 | +--- |
| 36 | + |
| 37 | +## Do Not Miss |
| 38 | +- [**Visual Studio code snippets**](https://github.com/debug-sharp/codesnippets) |
| 39 | + Download and install predefined VS snippets for most offten `Desharp` calls. |
| 40 | +- [**Visual Studio opener**](https://github.com/debug-sharp/editor-opener) |
| 41 | + Automatic Visual Studio (or any other) editor opening on specific file and line from rendered logs and exceptions. |
| 42 | + |
| 43 | +--- |
| 44 | + |
| 45 | +## Basic Dumping & Logging Any Structuralized Variables |
| 46 | + |
| 47 | +```cs |
| 48 | +using Desharp; |
| 49 | +using System.Collections.Generic; |
| 50 | + |
| 51 | +var list = new List<int?>() { 100, 200, null }; |
| 52 | +Debug.Dump(list); // print list by Console.WriteLine(); or append into html response as floating window |
| 53 | +Debug.Log(list); // store dumped list in debug.log or debug.html file on HDD |
| 54 | +``` |
| 55 | + |
| 56 | +Dumped result for both languages: |
| 57 | +``` |
| 58 | +[List<Int32?>[3]] |
| 59 | + 0: 100 [Int32] |
| 60 | + 1: 200 [Int32] |
| 61 | + 2: null |
| 62 | +``` |
| 63 | + |
| 64 | +## Basic Dumping & Logging Exceptions |
| 65 | + |
| 66 | +```cs |
| 67 | +try { |
| 68 | + throw new Exception("Something wrong!"); |
| 69 | +} catch (Exception e) { |
| 70 | + Debug.Dump(e); // print exception by Console.WriteLine(); or append into html response as floating window |
| 71 | + Debug.Log(e); // store dumped exception in exception.log or exception.html file on HDD |
| 72 | +} |
| 73 | +``` |
| 74 | + |
| 75 | +Dumped result for both languages: |
| 76 | +``` |
| 77 | +System.Exception (Hash Code: 50632145): |
| 78 | + Message : Something wrong! |
| 79 | + Time : 2017-06-10 13:18:07:300 |
| 80 | + Process ID: 7972 |
| 81 | + Thread ID : 1 |
| 82 | + File : /Program.cs:8 |
| 83 | + ------- |
| 84 | + 4 | namespace ExampleConsole { |
| 85 | + 5 | class Program { |
| 86 | + 6 | static void Main(string[] args) { |
| 87 | + 7 | try { |
| 88 | + -> 8 | throw new Exception("Something wrong!"); |
| 89 | + 9 | } catch (Exception e) { |
| 90 | + 10 | Debug.Dump(e); // print exception by Console.WriteLine(); or append into html response as floating window |
| 91 | + 11 | Debug.Log(e); // store dumped exception in exception.log or exception.html file on HDD |
| 92 | + 12 | } |
| 93 | + ------- |
| 94 | + Callstack: |
| 95 | + ExampleConsole.Program.Main(String[] args) /Program.cs 8 |
| 96 | +``` |
| 97 | + |
| 98 | +## All Dump Methods |
| 99 | + |
| 100 | +Dump any values to application output (in web applications into debug bar, |
| 101 | +in desktop applications into console or debug output window) |
| 102 | +```cs |
| 103 | +Desharp.Debug.Dump(params object[] args); |
| 104 | +``` |
| 105 | + |
| 106 | +Dump exception instance to application output if output dumping is enabled. It renders: |
| 107 | +- exception type, exception message and exception hash id |
| 108 | +- yes/no if exception has been caught or not caught |
| 109 | +- error file where exception has been thrown |
| 110 | +- thread call stack |
| 111 | +All inner exceptions after this exception in the same way. |
| 112 | +```cs |
| 113 | +Desharp.Debug.Dump(Exception exception = null, DumpOptions? options = default(DumpOptions?)); |
| 114 | +``` |
| 115 | + |
| 116 | +Dump any values to application output (in web applications into debug bar, |
| 117 | +in desktop applications into console or debug output window) |
| 118 | +This method dumps only single object with dump options like to dump |
| 119 | +different object depth as usual, different string length or to dump source location and more... |
| 120 | +```cs |
| 121 | +Desharp.Debug.Dump(object obj, DumpOptions? options = default(DumpOptions?)); |
| 122 | +``` |
| 123 | + |
| 124 | +Dump any type value to direct application output (not into web request debug |
| 125 | +bar in web applications!) and stop request/thread (in web applications dump into |
| 126 | +direct response body, in desktop applications into console or debug output window). |
| 127 | +```cs |
| 128 | +Desharp.Debug.DumpAndDie(object obj = null, DumpOptions? options = default(DumpOptions?)); |
| 129 | +``` |
| 130 | + |
| 131 | +## All Log Methods |
| 132 | + |
| 133 | +Log exception instance as dumped string into exceptions.log|exceptions.html file. It stores: |
| 134 | +- exception type |
| 135 | +- exception message |
| 136 | +- if exception has been caught or not caught |
| 137 | +- exception hash id |
| 138 | +- error file where exception has been thrown |
| 139 | +- thread call stack |
| 140 | +All inner exceptions after this exception in the same way. |
| 141 | +```cs |
| 142 | +Desharp.Debug.Log(Exception exception = null); |
| 143 | +``` |
| 144 | + |
| 145 | +Log any type value to application *.log|*.html file, specified by level param. |
| 146 | +```cs |
| 147 | +Desharp.Debug.Log(object obj = null, Level level = Level.INFO, int maxDepth = 0, int maxLength = 0); |
| 148 | +``` |
| 149 | + |
| 150 | +## All Other Methods |
| 151 | + |
| 152 | +Print to application output or log into file (if enabled) first param to be true |
| 153 | +or not and describe what was equal or not in first param by second param message. |
| 154 | +```cs |
| 155 | +Desharp.Debug.Assert(bool assertion, string description = "", Level logLevel = Level.DEBUG); |
| 156 | +``` |
| 157 | + |
| 158 | +Configure Desharp assembly from running application environment and override |
| 159 | +any XML config settings or automatically detected settings. |
| 160 | +```cs |
| 161 | +Desharp.Debug.Configure(DebugConfig cfg); |
| 162 | +``` |
| 163 | + |
| 164 | +Enable or disable variables dumping from application code environment for all threads |
| 165 | +or get enabled/disabled Desharp dumping state if no boolean param provided. |
| 166 | +```cs |
| 167 | +Desharp.Debug.Enabled(bool? enabled = default(bool?)); |
| 168 | +``` |
| 169 | + |
| 170 | +Return last uncaught Exception in request, mostly used in web applications by |
| 171 | +error page rendering process to know something about Exception before. |
| 172 | +```cs |
| 173 | +Desharp.Debug.GetLastError(); |
| 174 | +``` |
| 175 | + |
| 176 | +Return spent request processing time for web applications or return application |
| 177 | +up time for all other platforms. |
| 178 | +```cs |
| 179 | +Desharp.Debug.GetProcessingTime(); |
| 180 | +``` |
| 181 | + |
| 182 | +Print current thread stack trace into application output and exit running application. |
| 183 | +In web applications - stop current request, in any other applications - stop application |
| 184 | +with all it's threads and exit. |
| 185 | +```cs |
| 186 | +Desharp.Debug.Stop(); |
| 187 | +``` |
| 188 | + |
| 189 | +Prints to output or into log file number of seconds from last timer call under |
| 190 | +called name in seconds with 3 floating point decimal spaces. |
| 191 | +If no name specified or name is empty string, there is returned: |
| 192 | +Web applications - number of seconds from request beginning. |
| 193 | +Desktop applications - number of seconds from application start. |
| 194 | +```cs |
| 195 | +Desharp.Debug.Timer(string name = null, bool returnTimerSeconds = false, Level logLevel = Level.DEBUG); |
| 196 | +``` |
0 commit comments