Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
swdev:dotnet:debugging [2011/03/25 09:33] smayr |
swdev:dotnet:debugging [2011/08/30 16:34] (current) smayr [Debugging] |
||
---|---|---|---|
Line 1: | Line 1: | ||
== Debugging == | == Debugging == | ||
+ | |||
+ | * Enable WPF debug output. In Visual Studio, Options > Debugging > Output Window > WPF Trace Settings > Data Binding > All. | ||
+ | * Add a high TraceLevel to your binding: <code csharp> | ||
+ | * Run application, | ||
+ | * Add '' | ||
+ | * [[swdev: | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
== Using System.Diagnostics == | == Using System.Diagnostics == | ||
+ | === Configuration File === | ||
Add the following to the ''// | Add the following to the ''// | ||
<code xml> | <code xml> | ||
Line 9: | Line 22: | ||
< | < | ||
< | < | ||
- | <source name="srcEzFITDebug" switchName=" | + | <source name="srcMyAppDebug" switchName=" |
< | < | ||
- | <add name="textListener" /> | + | <add name="myTextListener" /> |
</ | </ | ||
</ | </ | ||
Line 19: | Line 32: | ||
</ | </ | ||
< | < | ||
- | <add name="textListener" | + | <add name="myTextListener" |
| | ||
| | ||
Line 27: | Line 40: | ||
</ | </ | ||
+ | </ | ||
+ | |||
+ | The '' | ||
+ | <code csharp> | ||
+ | public enum SourceLevels | ||
+ | { | ||
+ | All = -1, | ||
+ | Off = 0, | ||
+ | Critical | ||
+ | Error = 3, | ||
+ | Warning | ||
+ | Information | ||
+ | Verbose | ||
+ | ActivityTracing = 65280, | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | The listener could also be: | ||
+ | <code xml> | ||
+ | < | ||
+ | < | ||
+ | type=" | ||
+ | initializeData= " | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | === Writing Events === | ||
+ | |||
+ | To write to the event log: | ||
+ | <code csharp> | ||
+ | System.Diagnostics.Trace.TraceInformation(" | ||
+ | System.Diagnostics.Trace.TraceError(" | ||
+ | </ | ||
+ | |||
+ | Alternatively, | ||
+ | <code csharp> | ||
+ | TraceSource srcMyApp = new TraceSource(" | ||
+ | srcMyApp.TraceInformation(" | ||
+ | srcMyApp.TraceEvent(TraceEventType.Error, | ||
+ | </ | ||
+ | |||
+ | The '' | ||
+ | <code csharp> | ||
+ | public enum TraceEventType | ||
+ | { | ||
+ | Critical | ||
+ | Error = 2, | ||
+ | Warning | ||
+ | Information = 8, | ||
+ | Verbose | ||
+ | Start = 256, | ||
+ | Stop = 512, | ||
+ | Suspend | ||
+ | Resume | ||
+ | Transfer | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Another example: | ||
+ | <code csharp> | ||
+ | using System.Diagnostics; | ||
+ | |||
+ | private void WriteToEventLog(string message) | ||
+ | { | ||
+ | string cs = " | ||
+ | EventLog elog = new EventLog(); | ||
+ | |||
+ | if (!EventLog.SourceExists(cs)) | ||
+ | { | ||
+ | | ||
+ | } | ||
+ | |||
+ | elog.Source = cs; | ||
+ | elog.EnableRaisingEvents = true; | ||
+ | elog.WriteEntry(message); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Another example (by Microsoft): | ||
+ | <code csharp> | ||
+ | using System; | ||
+ | using System.Diagnostics; | ||
+ | using System.Threading; | ||
+ | |||
+ | class MySample{ | ||
+ | |||
+ | public static void Main(){ | ||
+ | |||
+ | // Create the source, if it does not already exist. | ||
+ | if(!EventLog.SourceExists(" | ||
+ | { | ||
+ | //An event log source should not be created and immediately used. | ||
+ | // | ||
+ | // | ||
+ | // | ||
+ | EventLog.CreateEventSource(" | ||
+ | Console.WriteLine(" | ||
+ | Console.WriteLine(" | ||
+ | // The source is created. | ||
+ | return; | ||
+ | } | ||
+ | |||
+ | // Create an EventLog instance and assign its source. | ||
+ | EventLog myLog = new EventLog(); | ||
+ | myLog.Source = " | ||
+ | |||
+ | // Write an informational entry to the event log. | ||
+ | myLog.WriteEntry(" | ||
+ | |||
+ | } | ||
+ | } | ||
</ | </ |