Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / wpf / src / Framework / MS / Internal / Utility / TraceLog.cs / 1 / TraceLog.cs
//---------------------------------------------------------------------------- // //// Copyright (C) Microsoft Corporation. All rights reserved. // // // Description: Log of recent actions. Use this to debug those nasty problems // that don't repro on demand and don't have enough information in a crash // dump. // // In the class(es) of interest, add a TraceLog object. At points of // interest, call TraceLog.Add to record a string in the log. After the // crash, call TraceLog.WriteLog (or simply examine the log directly in // the debugger). Log entries are timestamped. // //--------------------------------------------------------------------------- using System; using System.Collections; using System.Globalization; namespace MS.Internal.Utility { internal class TraceLog { // create an unbounded trace log internal TraceLog() : this(Int32.MaxValue) {} // create a trace log that remembers the last 'size' actions internal TraceLog(int size) { _size = size; _log = new ArrayList(); } // add an entry to the log. Args are just like String.Format internal void Add(string message, params object[] args) { // create timestamped message string string s = DateTime.Now.Ticks.ToString(CultureInfo.InvariantCulture) + " " + String.Format(CultureInfo.InvariantCulture, message, args); // if log is full, discard the oldest message if (_log.Count == _size) _log.RemoveAt(0); // add the new message _log.Add(s); } // write the log to the console internal void WriteLog() { for (int k=0; k<_log.Count; ++k) Console.WriteLine(_log[k]); } // return a printable id for the object internal static string IdFor(object o) { if (o == null) return "NULL"; else return String.Format(CultureInfo.InvariantCulture, "{0}.{1}", o.GetType().Name, o.GetHashCode()); } ArrayList _log; int _size; } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. //---------------------------------------------------------------------------- // //// Copyright (C) Microsoft Corporation. All rights reserved. // // // Description: Log of recent actions. Use this to debug those nasty problems // that don't repro on demand and don't have enough information in a crash // dump. // // In the class(es) of interest, add a TraceLog object. At points of // interest, call TraceLog.Add to record a string in the log. After the // crash, call TraceLog.WriteLog (or simply examine the log directly in // the debugger). Log entries are timestamped. // //--------------------------------------------------------------------------- using System; using System.Collections; using System.Globalization; namespace MS.Internal.Utility { internal class TraceLog { // create an unbounded trace log internal TraceLog() : this(Int32.MaxValue) {} // create a trace log that remembers the last 'size' actions internal TraceLog(int size) { _size = size; _log = new ArrayList(); } // add an entry to the log. Args are just like String.Format internal void Add(string message, params object[] args) { // create timestamped message string string s = DateTime.Now.Ticks.ToString(CultureInfo.InvariantCulture) + " " + String.Format(CultureInfo.InvariantCulture, message, args); // if log is full, discard the oldest message if (_log.Count == _size) _log.RemoveAt(0); // add the new message _log.Add(s); } // write the log to the console internal void WriteLog() { for (int k=0; k<_log.Count; ++k) Console.WriteLine(_log[k]); } // return a printable id for the object internal static string IdFor(object o) { if (o == null) return "NULL"; else return String.Format(CultureInfo.InvariantCulture, "{0}.{1}", o.GetType().Name, o.GetHashCode()); } ArrayList _log; int _size; } } // 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
- PenThreadWorker.cs
- MenuCommand.cs
- TypeForwardedToAttribute.cs
- GridItemProviderWrapper.cs
- EditorZoneBase.cs
- RoutedPropertyChangedEventArgs.cs
- PackageDigitalSignatureManager.cs
- FilteredSchemaElementLookUpTable.cs
- FocusTracker.cs
- MouseGestureConverter.cs
- ProgressChangedEventArgs.cs
- CommonProperties.cs
- TextBoxAutoCompleteSourceConverter.cs
- PermissionSet.cs
- RangeExpression.cs
- IDQuery.cs
- WebPartCollection.cs
- ListSortDescriptionCollection.cs
- OleDbStruct.cs
- IndexerNameAttribute.cs
- HttpBufferlessInputStream.cs
- Brushes.cs
- HealthMonitoringSection.cs
- ObjectPersistData.cs
- VariableQuery.cs
- SEHException.cs
- XamlNamespaceHelper.cs
- ProcessThreadDesigner.cs
- SqlDependencyListener.cs
- ReadContentAsBinaryHelper.cs
- XmlSerializerFactory.cs
- ResourcePermissionBaseEntry.cs
- PersistenceException.cs
- XsltLibrary.cs
- ReliableOutputSessionChannel.cs
- RemotingSurrogateSelector.cs
- CompilerErrorCollection.cs
- OptimizedTemplateContentHelper.cs
- MobileContainerDesigner.cs
- ChannelSinkStacks.cs
- MaskInputRejectedEventArgs.cs
- Span.cs
- XmlILOptimizerVisitor.cs
- DataGridViewCellStyle.cs
- SqlExpressionNullability.cs
- SoapExtensionTypeElementCollection.cs
- PrintDialogException.cs
- SimpleHandlerFactory.cs
- WindowsEditBox.cs
- TemplateFactory.cs
- ConnectionConsumerAttribute.cs
- DataGridCheckBoxColumn.cs
- DataTableMapping.cs
- QilIterator.cs
- TreeIterator.cs
- HtmlUtf8RawTextWriter.cs
- WorkflowOwnerAsyncResult.cs
- TransformerTypeCollection.cs
- HtmlTableRowCollection.cs
- EventLogPermissionEntry.cs
- ParseHttpDate.cs
- TypeConverters.cs
- SectionVisual.cs
- GestureRecognizer.cs
- AmbientProperties.cs
- TTSEngineTypes.cs
- TableCellCollection.cs
- CodeNamespace.cs
- SubMenuStyle.cs
- MarshalByRefObject.cs
- SoapEnumAttribute.cs
- CodeIterationStatement.cs
- ArrayTypeMismatchException.cs
- ChildDocumentBlock.cs
- ObjectToModelValueConverter.cs
- SQLSingleStorage.cs
- Material.cs
- DES.cs
- RangeValuePattern.cs
- PlatformCulture.cs
- LinqDataSourceSelectEventArgs.cs
- ContentType.cs
- FileUtil.cs
- CodeTypeOfExpression.cs
- DateTimeSerializationSection.cs
- MenuScrollingVisibilityConverter.cs
- CoTaskMemHandle.cs
- WhitespaceRule.cs
- ChannelDispatcherCollection.cs
- DataServiceQueryProvider.cs
- SpellerError.cs
- ReaderWriterLockWrapper.cs
- Oid.cs
- SqlNodeAnnotation.cs
- WorkflowMarkupSerializationManager.cs
- XmlNamespaceMapping.cs
- FileLogRecordHeader.cs
- State.cs
- WebHttpSecurityModeHelper.cs
- UnaryExpression.cs