Skip to Main Content
C# Cookbook, 2nd Edition
book

C# Cookbook, 2nd Edition

by Jay Hilyard, Stephen Teilhet
January 2006
Intermediate to advanced content levelIntermediate to advanced
1184 pages
43h 23m
English
O'Reilly Media, Inc.
Content preview from C# Cookbook, 2nd Edition
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
434
|
Chapter 8: Diagnostics
reproduce on your development machine. Knowing this, you want an application
with built-in instrumentation that’s off by default but can easily be turned on when
you need it.
Solution
Use the Trace class for any tracing code that you might need to turn on after your
application has been deployed. To turn on tracing at a client’s site, provide the client
with an application configuration file such as this one:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.diagnostics>
<switches>
<add name="DatabaseSwitch" value="4"/>
<!-- 4 == TraceLevel.Verbose -->
</switches>
<trace autoflush = "true" indentsize = "2">
<listeners>
<add name = "MyListener"
type = "System.Diagnostics.TextWriterTraceListener"
initializeData = " MyFileName.log"/>
</listeners>
</trace>
</system.diagnostics>
</configuration>
Discussion
Allowing tracing code to be enabled and used at a client site can be extremely useful
when debugging problems in release code. This technique is even more useful when
the problem cannot easily be reproduced in-house. For this reason, it is—in some
cases—a wise practice to use the
Trace class instead of the Debug class when adding
tracing code to your application.
To control the trace output at a client site, you can use an XML config file. This XML ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

C# Cookbook

C# Cookbook

Joe Mayo
C# Cookbook

C# Cookbook

Stephen Teilhet, Jay Hilyard
Head First C#, 4th Edition

Head First C#, 4th Edition

Andrew Stellman, Jennifer Greene

Publisher Resources

ISBN: 0596100639Supplemental ContentCatalog PageErrata