Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / Tools / xws_reg / System / ServiceModel / Install / MsiStyleLogWriter.cs / 1 / MsiStyleLogWriter.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.ServiceModel.Install { using System.Diagnostics; using System.Globalization; using System.IO; class MsiStyleLogWriter { string logEntryPrefix; bool logFailureReported; StreamWriter logWriter; MsiStyleLogWriter(string logEntryPrefix) { this.logEntryPrefix = logEntryPrefix; string tempPath = Path.GetTempPath(); Random random = new Random(); int attempts = 0; const int maxAttempts = 20; Exception lastException = null; do { string logFileName = string.Format(CultureInfo.InvariantCulture, "dd_wcf_retCA{0:X}.txt", random.Next(short.MaxValue)); string logFilePath = Path.Combine(tempPath, logFileName); try { Stream logFileStream = new FileStream(logFilePath, FileMode.CreateNew, FileAccess.Write, FileShare.Read); this.logWriter = new StreamWriter(logFileStream); } catch (DirectoryNotFoundException exception) { EventLogger.LogWarning(SR.GetString(SR.ErrorCreatingMsiStyleLogFile, logFilePath, exception), false); return; } catch (PathTooLongException exception) { EventLogger.LogWarning(SR.GetString(SR.ErrorCreatingMsiStyleLogFile, logFilePath, exception), false); return; } catch (IOException exception) { // The current logFilePath may already exists; try again. lastException = exception; } } while ((this.logWriter == null) && (++attempts < maxAttempts)); if (this.logWriter == null) { EventLogger.LogWarning(SR.GetString(SR.ErrorCreatingMsiStyleLogFile, tempPath, lastException), false); this.logWriter = StreamWriter.Null; } } public static MsiStyleLogWriter CreateWriter() { string mainModuleFilePath = Process.GetCurrentProcess().MainModule.FileName; string logEntryPrefix = Path.GetFileNameWithoutExtension(mainModuleFilePath); MsiStyleLogWriter writer = new MsiStyleLogWriter(logEntryPrefix); DateTime now = DateTime.Now; writer.WriteRaw(SR.GetString(SR.MsiStyleLogBanner, now.ToShortDateString(), now.ToString("HH:mm:ss", CultureInfo.CurrentCulture), mainModuleFilePath)); return writer; } public void WriteEntry(string message) { this.WriteRaw(string.Format(CultureInfo.InvariantCulture, "{0} [{1}]: {2}", this.logEntryPrefix, DateTime.Now.ToString("HH:mm:ss:fff", CultureInfo.CurrentCulture), message)); } public void WriteRaw(string message) { try { this.logWriter.WriteLine(message); this.logWriter.Flush(); } catch (IOException exception) { if (!this.logFailureReported) { EventLogger.WriteLogEntry(SR.GetString(SR.ErrorWritingMsiStyleLogEntry, exception), EventLogEntryType.Warning); this.logFailureReported = true; } } } } } // 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
- Rect3D.cs
- EncryptedPackageFilter.cs
- MappingException.cs
- XmlRootAttribute.cs
- RequestCacheEntry.cs
- KeySplineConverter.cs
- OleDbConnectionPoolGroupProviderInfo.cs
- PasswordPropertyTextAttribute.cs
- WindowsGrip.cs
- FormClosedEvent.cs
- SurrogateSelector.cs
- LoginName.cs
- PageStatePersister.cs
- XamlStackWriter.cs
- ModelItemKeyValuePair.cs
- ReliabilityContractAttribute.cs
- AttachedPropertiesService.cs
- Pair.cs
- SplitterCancelEvent.cs
- SqlNamer.cs
- GroupAggregateExpr.cs
- Int32AnimationUsingKeyFrames.cs
- MSHTMLHostUtil.cs
- Object.cs
- Roles.cs
- Connector.cs
- PropertyToken.cs
- SortedList.cs
- XmlArrayItemAttributes.cs
- RegexWorker.cs
- TypeToStringValueConverter.cs
- DataControlPagerLinkButton.cs
- DataGridViewCellCollection.cs
- XmlSerializerVersionAttribute.cs
- DataGridTablesFactory.cs
- LineSegment.cs
- _IPv6Address.cs
- ChunkedMemoryStream.cs
- RegularExpressionValidator.cs
- WmpBitmapDecoder.cs
- DomNameTable.cs
- LoginDesigner.cs
- XmlSchemaGroup.cs
- QilReplaceVisitor.cs
- TextDecorationCollectionConverter.cs
- WebPartDisplayMode.cs
- Schema.cs
- ProfileModule.cs
- SessionStateModule.cs
- Label.cs
- SizeChangedInfo.cs
- DispatcherEventArgs.cs
- XmlResolver.cs
- dbdatarecord.cs
- HandlerBase.cs
- MultipleCopiesCollection.cs
- Empty.cs
- SoapObjectWriter.cs
- Int32RectConverter.cs
- Vector3D.cs
- AutoSizeComboBox.cs
- String.cs
- DataServiceKeyAttribute.cs
- XmlName.cs
- ListDictionaryInternal.cs
- LoaderAllocator.cs
- HttpModuleCollection.cs
- XmlNamespaceManager.cs
- StatusCommandUI.cs
- WindowsStartMenu.cs
- FacetValueContainer.cs
- DataGridViewCellStyleConverter.cs
- Vector3DConverter.cs
- SessionIDManager.cs
- RelatedPropertyManager.cs
- DataGridViewEditingControlShowingEventArgs.cs
- FlowDocumentFormatter.cs
- documentsequencetextview.cs
- OleDbCommandBuilder.cs
- ImageSourceConverter.cs
- GZipDecoder.cs
- CodeTryCatchFinallyStatement.cs
- ISO2022Encoding.cs
- TreeWalkHelper.cs
- PointConverter.cs
- Graphics.cs
- NativeMethods.cs
- DocumentGrid.cs
- ServiceManager.cs
- XslAst.cs
- printdlgexmarshaler.cs
- X509ScopedServiceCertificateElement.cs
- DBSchemaTable.cs
- HotSpotCollection.cs
- SymmetricAlgorithm.cs
- FloaterParaClient.cs
- HttpRuntimeSection.cs
- DynamicExpression.cs
- DashStyles.cs
- ToolBarOverflowPanel.cs