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:43] 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 11: | Line 24: | ||
<source name=" | <source name=" | ||
< | < | ||
- | <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, | ||
+ | } | ||
</ | </ | ||
Line 37: | Line 65: | ||
</ | </ | ||
</ | </ | ||
+ | |||
+ | === Writing Events === | ||
To write to the event log: | To write to the event log: | ||
Line 46: | Line 76: | ||
Alternatively, | Alternatively, | ||
<code csharp> | <code csharp> | ||
- | TraceSource srcMyApp = new TraceSource(" | + | TraceSource srcMyApp = new TraceSource(" |
srcMyApp.TraceInformation(" | srcMyApp.TraceInformation(" | ||
srcMyApp.TraceEvent(TraceEventType.Error, | srcMyApp.TraceEvent(TraceEventType.Error, | ||
Line 68: | Line 98: | ||
</ | </ | ||
- | The '' | + | Another example: |
<code csharp> | <code csharp> | ||
- | public enum SourceLevels | + | using System.Diagnostics; |
+ | |||
+ | private void WriteToEventLog(string message) | ||
{ | { | ||
- | All = -1, | + | string cs = " |
- | | + | |
- | | + | |
- | | + | 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{ | ||
+ | |||
+ | | ||
+ | |||
+ | // Create the source, if it does not already exist. | ||
+ | | ||
+ | { | ||
+ | //An event log source should not be created and immediately used. | ||
+ | // | ||
+ | //prior to executing the application that uses the source. | ||
+ | // | ||
+ | EventLog.CreateEventSource(" | ||
+ | | ||
+ | Console.WriteLine(" | ||
+ | // The source is created. | ||
+ | return; | ||
+ | } | ||
+ | |||
+ | // Create an EventLog instance and assign its source. | ||
+ | EventLog myLog = new EventLog(); | ||
+ | | ||
+ | |||
+ | // Write an informational entry to the event log. | ||
+ | myLog.WriteEntry(" | ||
+ | |||
+ | } | ||
} | } | ||
</ | </ |