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:42] 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 55: | Line 85: | ||
public enum TraceEventType | public enum TraceEventType | ||
{ | { | ||
- | Critical = 1, | + | Critical |
- | Error = 2, | + | Error |
- | Warning = 4, | + | Warning |
Information = 8, | Information = 8, | ||
- | Verbose = 16, | + | Verbose |
- | Start = 256, | + | Start |
- | Stop = 512, | + | Stop = 512, |
- | Suspend = 1024, | + | Suspend |
- | Resume = 2048, | + | Resume |
- | Transfer = 4096, | + | Transfer |
} | } | ||
</ | </ | ||
- | 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 | ||
+ | | ||
+ | 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(); | ||
+ | myLog.Source = " | ||
+ | |||
+ | // Write an informational entry to the event log. | ||
+ | myLog.WriteEntry(" | ||
+ | |||
+ | } | ||
} | } | ||
</ | </ |