As we can see in Silverlight 2.0 beta 1 developers forgot about including well known .Net class Trace from System.Diagnostics. Therefore it is difficult to output debugging messages into log and analyse it. Log can help greatly in performance optimization tasks for example.
New Elisy.Scab.Services.Trace class was introduced in form of
SCAB (Silverlight Composite Application Block) module on this web site. You can download source code from attachment to this post. You can disconnect it from Scab commenting public class TraceModule : Module class and its implementation.
Elisy.Scab.Services.Trace class description
Class configuration can be made through two properties: public string DestinationId and public
HtmlElement Destination. The first property stores html page element Id and the secont stores the pointer to the html element. You can set either of this properties. If you set nothing or html page has not element with the DestinationId class creates new div element itself and adds it to the body end. Messages will be written into configured or created destination element.
Additional property public int IndentLevel allows to generate white space delimiters in messages. You can manage it through IndentLevel++ and IndentLevel--.
public void Write(string message) – writes string parameter into destination html element.
public void WriteHtml(string html) – writes html fragment into destination html element.
public void WriteLine(string message) – writes string parameter and adds line break (<br/>)
All the 3 methods work with destination element innerHTML property. Write and WriteLine take into account IndentLevel and write delimeters accorting it.
Examples
Trace trace = new Trace();
trace.WriteLine("Message Line 1");
trace.Write("Message 2");
trace.WriteLine("Message 3");
trace.WriteHtml("<p>Message 4 as Html</p>");
trace.IndentLevel++;
trace.WriteLine("Message 5 with separator");
Results:
Message Line 1
Message 2Message 3
Message 4 as Html
Message 5 with separator
Trace.cs (3.90 kb)
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5