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:45] 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 52: | Line 65: | ||
</ | </ | ||
</ | </ | ||
+ | |||
+ | === Writing Events === | ||
To write to the event log: | To write to the event log: | ||
Line 61: | 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 83: | Line 98: | ||
</ | </ | ||
+ | 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(" | ||
+ | |||
+ | } | ||
+ | } | ||
+ | </ |