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
- MethodBuilder.cs
- ProvideValueServiceProvider.cs
- XmlLoader.cs
- ModelUtilities.cs
- KeySpline.cs
- GestureRecognizer.cs
- TextBoxAutoCompleteSourceConverter.cs
- SafeFileHandle.cs
- SystemIPGlobalStatistics.cs
- DesignerLoader.cs
- CommandEventArgs.cs
- OleDbInfoMessageEvent.cs
- SequentialWorkflowRootDesigner.cs
- CachedFontFace.cs
- CheckBoxList.cs
- ConstrainedDataObject.cs
- ConsumerConnectionPoint.cs
- RuntimeTrackingProfile.cs
- DataReceivedEventArgs.cs
- XmlAnyAttributeAttribute.cs
- PropertyPushdownHelper.cs
- ButtonBaseAutomationPeer.cs
- MailMessageEventArgs.cs
- xmlfixedPageInfo.cs
- ToolStripItemTextRenderEventArgs.cs
- PngBitmapDecoder.cs
- DataSourceControlBuilder.cs
- PersonalizationEntry.cs
- RefreshEventArgs.cs
- WindowsMenu.cs
- SubqueryRules.cs
- CounterSample.cs
- MsmqReceiveHelper.cs
- EventMappingSettingsCollection.cs
- DbFunctionCommandTree.cs
- COM2EnumConverter.cs
- GeneralTransform3DTo2DTo3D.cs
- Graphics.cs
- ToolStripProgressBar.cs
- SynchronizedReadOnlyCollection.cs
- FunctionDetailsReader.cs
- DesignerForm.cs
- ActivatedMessageQueue.cs
- RequestNavigateEventArgs.cs
- WasAdminWrapper.cs
- Vertex.cs
- SpecialTypeDataContract.cs
- EtwTrace.cs
- HyperLinkStyle.cs
- HostingEnvironmentWrapper.cs
- FlowDocumentScrollViewer.cs
- ByteAnimationBase.cs
- DockAndAnchorLayout.cs
- ResXResourceWriter.cs
- CharacterMetricsDictionary.cs
- ZipArchive.cs
- UTF7Encoding.cs
- CodeSnippetStatement.cs
- RadioButton.cs
- UnknownBitmapDecoder.cs
- SafeNativeMethodsMilCoreApi.cs
- baseaxisquery.cs
- Matrix.cs
- TreeNodeStyleCollection.cs
- MessageBox.cs
- FederatedMessageSecurityOverHttp.cs
- ComponentResourceManager.cs
- PointAnimationUsingPath.cs
- DSASignatureFormatter.cs
- RowSpanVector.cs
- DateTimePicker.cs
- EventQueueState.cs
- RegistryKey.cs
- oledbmetadatacolumnnames.cs
- Simplifier.cs
- ButtonBase.cs
- ResponseBodyWriter.cs
- WebBrowserNavigatedEventHandler.cs
- EditorPart.cs
- XmlReaderSettings.cs
- DataObjectSettingDataEventArgs.cs
- RightsManagementEncryptedStream.cs
- DbInsertCommandTree.cs
- RenderContext.cs
- CodeGenerator.cs
- ServiceBuildProvider.cs
- NavigationFailedEventArgs.cs
- InheritanceContextHelper.cs
- ListViewItemSelectionChangedEvent.cs
- PrefixQName.cs
- SoapFormatter.cs
- CharUnicodeInfo.cs
- InstanceOwnerException.cs
- ComNativeDescriptor.cs
- InheritablePropertyChangeInfo.cs
- _CommandStream.cs
- FileDataSourceCache.cs
- Debug.cs
- EnlistmentState.cs
- XPathMessageFilterElementCollection.cs