Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WCF / SMDiagnostics / System / ServiceModel / Diagnostics / SafeEventLogWriteHandle.cs / 1305376 / SafeEventLogWriteHandle.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.ServiceModel.Diagnostics { using Microsoft.Win32.SafeHandles; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Globalization; using System.Diagnostics; using System.Security; using System.Runtime; [Fx.Tag.SecurityNote(Critical = "Usage of SafeHandleZeroOrMinusOneIsInvalid, which is protected by a LinkDemand and InheritanceDemand")] [SecurityCritical] sealed class SafeEventLogWriteHandle : SafeHandleZeroOrMinusOneIsInvalid { // Note: RegisterEventSource returns 0 on failure [Fx.Tag.SecurityNote(Critical = "Usage of SafeHandleZeroOrMinusOneIsInvalid, which is protected by a LinkDemand and InheritanceDemand")] [SecurityCritical] SafeEventLogWriteHandle() : base(true) { } [ResourceConsumption(ResourceScope.Machine)] [Fx.Tag.SecurityNote(Critical = "Usage of SafeHandleZeroOrMinusOneIsInvalid, which is protected by a LinkDemand and InheritanceDemand")] [SecurityCritical] internal static SafeEventLogWriteHandle RegisterEventSource(string uncServerName, string sourceName) { SafeEventLogWriteHandle retval = NativeMethods.RegisterEventSource(uncServerName, sourceName); int error = Marshal.GetLastWin32Error(); if (retval.IsInvalid) { Debug.Print("SafeEventLogWriteHandle::RegisterEventSource[" + uncServerName + ", " + sourceName + "] Failed. Last Error: " + error.ToString(CultureInfo.InvariantCulture)); } return retval; } [DllImport("advapi32", SetLastError = true)] [ResourceExposure(ResourceScope.None)] private static extern bool DeregisterEventSource(IntPtr hEventLog); #pragma warning disable 56523 [Fx.Tag.SecurityNote(Critical = "Usage of SafeHandleZeroOrMinusOneIsInvalid, which is protected by a LinkDemand and InheritanceDemand")] [SecurityCritical] override protected bool ReleaseHandle() { return DeregisterEventSource(this.handle); } #pragma warning restore 56523 } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.ServiceModel.Diagnostics { using Microsoft.Win32.SafeHandles; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Globalization; using System.Diagnostics; using System.Security; using System.Runtime; [Fx.Tag.SecurityNote(Critical = "Usage of SafeHandleZeroOrMinusOneIsInvalid, which is protected by a LinkDemand and InheritanceDemand")] [SecurityCritical] sealed class SafeEventLogWriteHandle : SafeHandleZeroOrMinusOneIsInvalid { // Note: RegisterEventSource returns 0 on failure [Fx.Tag.SecurityNote(Critical = "Usage of SafeHandleZeroOrMinusOneIsInvalid, which is protected by a LinkDemand and InheritanceDemand")] [SecurityCritical] SafeEventLogWriteHandle() : base(true) { } [ResourceConsumption(ResourceScope.Machine)] [Fx.Tag.SecurityNote(Critical = "Usage of SafeHandleZeroOrMinusOneIsInvalid, which is protected by a LinkDemand and InheritanceDemand")] [SecurityCritical] internal static SafeEventLogWriteHandle RegisterEventSource(string uncServerName, string sourceName) { SafeEventLogWriteHandle retval = NativeMethods.RegisterEventSource(uncServerName, sourceName); int error = Marshal.GetLastWin32Error(); if (retval.IsInvalid) { Debug.Print("SafeEventLogWriteHandle::RegisterEventSource[" + uncServerName + ", " + sourceName + "] Failed. Last Error: " + error.ToString(CultureInfo.InvariantCulture)); } return retval; } [DllImport("advapi32", SetLastError = true)] [ResourceExposure(ResourceScope.None)] private static extern bool DeregisterEventSource(IntPtr hEventLog); #pragma warning disable 56523 [Fx.Tag.SecurityNote(Critical = "Usage of SafeHandleZeroOrMinusOneIsInvalid, which is protected by a LinkDemand and InheritanceDemand")] [SecurityCritical] override protected bool ReleaseHandle() { return DeregisterEventSource(this.handle); } #pragma warning restore 56523 } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DataGridViewCellEventArgs.cs
- EventSourceCreationData.cs
- HttpStaticObjectsCollectionBase.cs
- HiddenField.cs
- MenuAdapter.cs
- XPathNavigatorReader.cs
- wmiprovider.cs
- CustomErrorCollection.cs
- WorkBatch.cs
- PointAnimation.cs
- XmlElement.cs
- InputDevice.cs
- BamlStream.cs
- EFTableProvider.cs
- DataStreamFromComStream.cs
- HijriCalendar.cs
- ContentDefinition.cs
- PointCollectionValueSerializer.cs
- EventProperty.cs
- LoadItemsEventArgs.cs
- WindowsTab.cs
- IISUnsafeMethods.cs
- DataBoundControlHelper.cs
- Compiler.cs
- CompilerGlobalScopeAttribute.cs
- Vector3DCollection.cs
- Walker.cs
- XmlSignatureProperties.cs
- AssociationType.cs
- ToolTip.cs
- SmtpMail.cs
- HebrewNumber.cs
- dbenumerator.cs
- ResolveRequestResponseAsyncResult.cs
- WinFormsSecurity.cs
- UnauthorizedAccessException.cs
- webeventbuffer.cs
- AccessKeyManager.cs
- WebBrowsableAttribute.cs
- XmlDataSourceNodeDescriptor.cs
- RootNamespaceAttribute.cs
- IndexOutOfRangeException.cs
- Cloud.cs
- AppDomainUnloadedException.cs
- InputLanguage.cs
- PointCollection.cs
- Selector.cs
- StackSpiller.Temps.cs
- PrivilegeNotHeldException.cs
- SByte.cs
- RemotingAttributes.cs
- JsonSerializer.cs
- EndPoint.cs
- LedgerEntry.cs
- ImportCatalogPart.cs
- TypeTypeConverter.cs
- DBSqlParser.cs
- EventMap.cs
- MD5CryptoServiceProvider.cs
- DelegateArgumentReference.cs
- Drawing.cs
- EventItfInfo.cs
- XamlToRtfWriter.cs
- ObjectReaderCompiler.cs
- GroupBox.cs
- XmlSchemaParticle.cs
- ProbeDuplexCD1AsyncResult.cs
- ColumnHeaderConverter.cs
- Vector.cs
- MouseOverProperty.cs
- TreeNodeBindingDepthConverter.cs
- MetadataCacheItem.cs
- Size.cs
- WebPartManager.cs
- GraphicsContext.cs
- odbcmetadatacolumnnames.cs
- AutomationPattern.cs
- ByteAnimationUsingKeyFrames.cs
- BitStack.cs
- DateTimeStorage.cs
- ItemList.cs
- WindowsAuthenticationModule.cs
- IMembershipProvider.cs
- LoginAutoFormat.cs
- InternalCache.cs
- ModifierKeysValueSerializer.cs
- OAVariantLib.cs
- ListDictionary.cs
- EditingContext.cs
- FormViewRow.cs
- PrefixQName.cs
- StringSorter.cs
- Avt.cs
- IDReferencePropertyAttribute.cs
- PriorityBinding.cs
- SqlUserDefinedAggregateAttribute.cs
- TraceHandler.cs
- AccessDataSourceWizardForm.cs
- ListViewTableRow.cs
- StringPropertyBuilder.cs