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
- IIS7WorkerRequest.cs
- ValidationManager.cs
- DataGridViewCellMouseEventArgs.cs
- DrawTreeNodeEventArgs.cs
- TextEditorTyping.cs
- TypefaceMap.cs
- ScrollBarRenderer.cs
- DesignerCapabilities.cs
- IconEditor.cs
- QuaternionIndependentAnimationStorage.cs
- SqlMultiplexer.cs
- TemplateControlParser.cs
- CompilerState.cs
- WhereQueryOperator.cs
- ProcessHost.cs
- DelegateTypeInfo.cs
- MDIClient.cs
- WebColorConverter.cs
- XmlUtilWriter.cs
- PointAnimationBase.cs
- ClientTargetSection.cs
- WebPartVerb.cs
- HwndMouseInputProvider.cs
- CodeVariableDeclarationStatement.cs
- _NestedMultipleAsyncResult.cs
- ComponentEditorForm.cs
- FormattedText.cs
- InkCanvasSelection.cs
- SafeCryptHandles.cs
- BufferedReadStream.cs
- DummyDataSource.cs
- controlskin.cs
- ListViewItem.cs
- ColorMap.cs
- CFGGrammar.cs
- StreamFormatter.cs
- xsdvalidator.cs
- ProfileSettings.cs
- Point3DConverter.cs
- ToolBarButtonClickEvent.cs
- TemplateControlBuildProvider.cs
- ResourceWriter.cs
- PolyQuadraticBezierSegmentFigureLogic.cs
- CompressionTransform.cs
- CompositeTypefaceMetrics.cs
- SRef.cs
- ConfigurationSectionGroup.cs
- ImmutableClientRuntime.cs
- ErrorBehavior.cs
- PopOutPanel.cs
- Rule.cs
- HttpDigestClientCredential.cs
- IssuedTokensHeader.cs
- SystemUdpStatistics.cs
- RegularExpressionValidator.cs
- CdpEqualityComparer.cs
- ProcessModelSection.cs
- WSSecurityPolicy12.cs
- InputScopeAttribute.cs
- PositiveTimeSpanValidatorAttribute.cs
- Stack.cs
- HexParser.cs
- EntityDataSourceEntityTypeFilterConverter.cs
- Binding.cs
- BitmapEffectInputData.cs
- Point4D.cs
- XmlBufferReader.cs
- ShapingEngine.cs
- SessionStateSection.cs
- webclient.cs
- HttpRequest.cs
- BuildProviderAppliesToAttribute.cs
- SqlInternalConnectionSmi.cs
- ConfigViewGenerator.cs
- LinqDataSourceStatusEventArgs.cs
- FontCollection.cs
- InputGestureCollection.cs
- SafeNativeMemoryHandle.cs
- XmlDeclaration.cs
- DataGridViewColumnStateChangedEventArgs.cs
- SqlXmlStorage.cs
- JoinElimination.cs
- AssemblyUtil.cs
- WindowsRichEditRange.cs
- CollectionViewGroupRoot.cs
- _Semaphore.cs
- _NegoStream.cs
- RoutedEventValueSerializer.cs
- PageThemeBuildProvider.cs
- AddInSegmentDirectoryNotFoundException.cs
- TypeElement.cs
- ArraySubsetEnumerator.cs
- AnnotationAuthorChangedEventArgs.cs
- SqlCommand.cs
- MenuEventArgs.cs
- BinaryReader.cs
- WebPartCollection.cs
- EntityDataSourceContextCreatedEventArgs.cs
- SocketInformation.cs
- WinCategoryAttribute.cs