public static void UninstallSecurityEventSource(string sourceName) { if (sourceName == null) { throw new ArgumentNullException(nameof(sourceName)); } if (!SourceNameValidator.IsSourceNameValid(sourceName)) { throw new ArgumentException("Invalid event source name", nameof(sourceName)); } try { if (false == Win32Native.AuthzUninstallSecurityEventSource(0, sourceName)) { int error = Marshal.GetLastWin32Error(); if (error == Win32Native.ERROR_NOT_ENOUGH_MEMORY) { throw new OutOfMemoryException(); } else if (error == Win32Native.ERROR_ACCESS_DENIED) { throw new UnauthorizedAccessException(); } else if (error == Win32Native.ERROR_FILE_NOT_FOUND) { // swallow this exception error = 0; } else { throw new Win32Exception(error); } } } catch (EntryPointNotFoundException) { throw new NotSupportedException("Platform not supported"); } }