Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / TransactionBridge / Microsoft / Transactions / Wsat / Messaging / DebugTraceHelper.cs / 1 / DebugTraceHelper.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace Microsoft.Transactions.Wsat.Messaging { using System; using System.Diagnostics; using System.Globalization; using System.Threading; using Microsoft.Transactions.Bridge; // A base class for formatting debug trace output. This class // ensures that all messages are formatted similarly, so that // output from multiple sources can be lined up, compared, and // correlated. An output message from this class looks like: // // 2003-11-21 18:52:24Z [ 808] [DRIVER ] : Awaiting recovery done... // // The fields are, from left to right: date, time, thread, // name, and message. // // The TraceSwitch constructor parameter indicates which trace // switch controls the trace output. The Name parameter provides // a tag for the compoent doing the tracing (DRIVER, in the above // example). For performance, you should probably create a static // instance of one of these and use it for everything. // // Each of the trace functions (TraceVerbose, TraceWarning, etc.) // can take a format string and parameters, ala String.Format. // The number of parameters, however, is limited to four. This is // because variable-length argument lists cause array allocations, // and the performance impact of these functions should be as // small as possible when tracing is disabled. // sealed class DebugTraceHelper { string name; TraceSwitch traceSwitch; public DebugTraceHelper(string name, TraceSwitch traceSwitch) { this.name = name; this.traceSwitch = traceSwitch; } string FormatMessage(string message) { return String.Format( CultureInfo.InvariantCulture, "{0} [{1,4:x8}] [{2}] : {3}", DateTime.Now.ToString( "u", DateTimeFormatInfo.InvariantInfo), Thread.CurrentThread.ManagedThreadId.ToString( "x", CultureInfo.InvariantCulture), this.name, message); } public void Trace(TraceLevel level, string message) { if (TraceEnabled(level)) { message = FormatMessage(message); System.Diagnostics.Trace.WriteLine(message); } } public void Trace(TraceLevel level, string message, object param0) { if (TraceEnabled(level)) { message = String.Format(CultureInfo.InvariantCulture, message, param0); message = FormatMessage(message); System.Diagnostics.Trace.WriteLine(message); } } public void Trace(TraceLevel level, string message, object param0, object param1) { if (TraceEnabled(level)) { message = String.Format(CultureInfo.InvariantCulture, message, param0, param1); message = FormatMessage(message); System.Diagnostics.Trace.WriteLine(message); } } public void Trace(TraceLevel level, string message, object param0, object param1, object param2) { if (TraceEnabled(level)) { message = String.Format(CultureInfo.InvariantCulture, message, param0, param1, param2); message = FormatMessage(message); System.Diagnostics.Trace.WriteLine(message); } } public void Trace(TraceLevel level, string message, object param0, object param1, object param2, object param3) { if (TraceEnabled(level)) { message = String.Format(CultureInfo.InvariantCulture, message, param0, param1, param2, param3); message = FormatMessage(message); System.Diagnostics.Trace.WriteLine(message); } } public bool TraceEnabled(TraceLevel level) { return (this.traceSwitch.Level >= level); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- XPathDescendantIterator.cs
- WhitespaceRuleLookup.cs
- ViewCellSlot.cs
- ConfigurationValidatorAttribute.cs
- WebConfigurationFileMap.cs
- CompilerError.cs
- HttpApplication.cs
- ResponseStream.cs
- coordinator.cs
- TrailingSpaceComparer.cs
- StyleCollectionEditor.cs
- ClientBuildManager.cs
- ContextDataSourceView.cs
- EntityContainerEntitySet.cs
- ClientTargetCollection.cs
- PropertyDescriptorComparer.cs
- KnownBoxes.cs
- BitmapMetadataBlob.cs
- ConstraintStruct.cs
- UnsafeNativeMethods.cs
- XmlTypeMapping.cs
- RenderData.cs
- SqlProfileProvider.cs
- Block.cs
- MissingFieldException.cs
- MenuStrip.cs
- Vector3DCollectionConverter.cs
- KeysConverter.cs
- CompilationAssemblyInstallComponent.cs
- XmlCharCheckingWriter.cs
- Encoder.cs
- EpmAttributeNameBuilder.cs
- ReferenceTypeElement.cs
- AllMembershipCondition.cs
- DBAsyncResult.cs
- UmAlQuraCalendar.cs
- ServiceAuthorizationBehavior.cs
- GridViewRowPresenter.cs
- X509CertificateClaimSet.cs
- ScriptControlManager.cs
- TransformGroup.cs
- PriorityBinding.cs
- DataReaderContainer.cs
- ValueType.cs
- ISAPIApplicationHost.cs
- TypeSystemHelpers.cs
- Transform3DGroup.cs
- HtmlInputText.cs
- BaseAddressElementCollection.cs
- CollectionView.cs
- SEHException.cs
- UIElementParaClient.cs
- GregorianCalendar.cs
- SecurityImpersonationBehavior.cs
- ProcessThreadCollection.cs
- Timer.cs
- TextBoxAutomationPeer.cs
- StylusPointProperty.cs
- QilPatternVisitor.cs
- ServicePointManagerElement.cs
- VisualBrush.cs
- AttachedPropertyMethodSelector.cs
- XmlSchemaExporter.cs
- PropertyEntry.cs
- BadImageFormatException.cs
- CallTemplateAction.cs
- StagingAreaInputItem.cs
- EventProviderTraceListener.cs
- XmlAttributeCache.cs
- RecognizerBase.cs
- FilterFactory.cs
- UriScheme.cs
- ErrorStyle.cs
- DataBoundControlHelper.cs
- EncodingDataItem.cs
- TdsParserSafeHandles.cs
- NativeActivityTransactionContext.cs
- DescendantBaseQuery.cs
- KnownTypeDataContractResolver.cs
- NativeRecognizer.cs
- User.cs
- InternalSafeNativeMethods.cs
- CheckBoxDesigner.cs
- HttpListenerRequestUriBuilder.cs
- SmtpNtlmAuthenticationModule.cs
- TargetParameterCountException.cs
- OracleConnectionStringBuilder.cs
- Utils.cs
- SpecialFolderEnumConverter.cs
- WebPartsSection.cs
- WebPartCatalogCloseVerb.cs
- SettingsProviderCollection.cs
- CapacityStreamGeometryContext.cs
- HttpPostedFileBase.cs
- VisualCollection.cs
- AvTrace.cs
- HierarchicalDataSourceDesigner.cs
- NumericUpDownAccelerationCollection.cs
- DocumentOrderComparer.cs
- RemoteWebConfigurationHostStream.cs