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
- XmlQualifiedName.cs
- BaseTypeViewSchema.cs
- TableCell.cs
- SchemaTableColumn.cs
- WindowsListViewGroupSubsetLink.cs
- QuaternionAnimation.cs
- PointUtil.cs
- AppDomainFactory.cs
- DataDocumentXPathNavigator.cs
- LicenseManager.cs
- KnownBoxes.cs
- ProcessModuleCollection.cs
- DTCTransactionManager.cs
- FixUpCollection.cs
- PropertyDescriptorComparer.cs
- Hash.cs
- ObjectPersistData.cs
- SerializationFieldInfo.cs
- SmtpFailedRecipientsException.cs
- BindingCompleteEventArgs.cs
- XAMLParseException.cs
- StaticSiteMapProvider.cs
- AppDomainManager.cs
- TextParaClient.cs
- SqlInternalConnection.cs
- SetIterators.cs
- DocumentSchemaValidator.cs
- DataBoundControlHelper.cs
- CharAnimationBase.cs
- CodeTypeParameterCollection.cs
- KnownBoxes.cs
- PersonalizationProvider.cs
- LoginName.cs
- SapiInterop.cs
- CodeTypeDelegate.cs
- ISAPIRuntime.cs
- BaseParser.cs
- WebPartZoneBase.cs
- PagedDataSource.cs
- ExpressionBuilder.cs
- SymmetricAlgorithm.cs
- DataTableReader.cs
- PropertiesTab.cs
- DependencyPropertyKind.cs
- DesignerCatalogPartChrome.cs
- SmiRecordBuffer.cs
- altserialization.cs
- StringFunctions.cs
- CallbackHandler.cs
- WorkflowMarkupSerializationProvider.cs
- WmfPlaceableFileHeader.cs
- QilGeneratorEnv.cs
- ParallelLoopState.cs
- RpcResponse.cs
- sqlcontext.cs
- EqualityComparer.cs
- PrincipalPermission.cs
- RemoteCryptoDecryptRequest.cs
- HttpGetProtocolImporter.cs
- IODescriptionAttribute.cs
- ExpandCollapseIsCheckedConverter.cs
- TextModifierScope.cs
- isolationinterop.cs
- ClientApiGenerator.cs
- DataGridViewRowCollection.cs
- GridSplitterAutomationPeer.cs
- ConstraintEnumerator.cs
- ProfessionalColorTable.cs
- WriteFileContext.cs
- CharacterMetricsDictionary.cs
- SmtpNetworkElement.cs
- ObjectListCommand.cs
- PolygonHotSpot.cs
- SystemNetHelpers.cs
- WebReferenceOptions.cs
- DataGridViewRowCollection.cs
- CreatingCookieEventArgs.cs
- HostingEnvironmentWrapper.cs
- Maps.cs
- ProfilePropertySettings.cs
- FixUpCollection.cs
- Panel.cs
- Grid.cs
- Logging.cs
- TextTreeTextBlock.cs
- VirtualDirectoryMapping.cs
- activationcontext.cs
- ISAPIApplicationHost.cs
- SqlDataSourceConfigureFilterForm.cs
- CloudCollection.cs
- PriorityRange.cs
- AppSettingsExpressionBuilder.cs
- MULTI_QI.cs
- ConfigDefinitionUpdates.cs
- Attachment.cs
- TabControlAutomationPeer.cs
- FileDialogPermission.cs
- UnmanagedHandle.cs
- XmlSchemaAttributeGroupRef.cs
- PrimarySelectionGlyph.cs