-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exceptions from EventRecordWrittenEventArgs are missing the original win32 error code #67702
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Tagging subscribers to this area: @tarekgh, @tommcdon, @pjanotti Issue DetailsDescriptionOne can retrieve a For example subscribing to an non existing log channel gives the error Reproduction StepsThe MRE below subscribes to a non existing channel yielding an exception in the private static void Test1()
{
var query = new EventLogQuery(null, PathType.LogName, "<QueryList><Query Id=\"0\"><Select Path=\"non-existing-channel\">*</Select></Query></QueryList>");
var watcher = new EventLogWatcher(query);
watcher.EventRecordWritten += Watcher_EventRecordWritten;
watcher.Enabled = true;
EventLog.WriteEntry("dummy source", "Dummy test message");
Thread.Sleep(1000 * 60);
watcher.Enabled = false;
Console.WriteLine("Test 1 completed");
}
private static void Watcher_EventRecordWritten(object sender, EventRecordWrittenEventArgs e)
{
if (e.EventRecord == null) {
Console.WriteLine(e.EventException.Message);
Console.WriteLine(e.EventException.HResult);
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(string.Format("HRESULT:0x{0:X8}", e.EventException.HResult));
Console.ForegroundColor = ConsoleColor.White;
} else
{
Console.WriteLine(e.EventRecord.FormatDescription());
e.EventRecord.Dispose();
}
} Expected behaviorThe Actual behaviorThe Regression?No response Known WorkaroundsNo response Configuration.NET 6 Other informationNo response
|
I see that the |
Tagging subscribers to this area: @dotnet/area-system-diagnostics-eventlog Issue DetailsDescriptionOne can retrieve a For example subscribing to an non existing log channel gives the error Reproduction StepsThe MRE below subscribes to a non existing channel yielding an exception in the private static void Test1()
{
var query = new EventLogQuery(null, PathType.LogName, "<QueryList><Query Id=\"0\"><Select Path=\"non-existing-channel\">*</Select></Query></QueryList>");
var watcher = new EventLogWatcher(query);
watcher.EventRecordWritten += Watcher_EventRecordWritten;
watcher.Enabled = true;
EventLog.WriteEntry("dummy source", "Dummy test message");
Thread.Sleep(1000 * 60);
watcher.Enabled = false;
Console.WriteLine("Test 1 completed");
}
private static void Watcher_EventRecordWritten(object sender, EventRecordWrittenEventArgs e)
{
if (e.EventRecord == null) {
Console.WriteLine(e.EventException.Message);
Console.WriteLine(e.EventException.HResult);
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(string.Format("HRESULT:0x{0:X8}", e.EventException.HResult));
Console.ForegroundColor = ConsoleColor.White;
} else
{
Console.WriteLine(e.EventRecord.FormatDescription());
e.EventRecord.Dispose();
}
} Expected behaviorThe Actual behaviorThe Regression?No response Known WorkaroundsNo response Configuration.NET 6 Other informationNo response
|
Description
One can retrieve a
HResult
error code fromSystem.Diagnostics.Eventing.Reader.EventRecordWrittenEventArgs.EventException
but it has no connection to the underlying win32 error code from theEvtNext
function used (https://github.com/microsoft/referencesource/blob/master/System.Core/System/Diagnostics/Eventing/Reader/EventLogWatcher.cs#L228).For example subscribing to an non existing log channel gives the error
The handle is invalid.
but theHResult
code is -2146233088 (0x80131500). The win32 API error code forERROR_INVALID_HANDLE
is 6 (0x6).Reproduction Steps
The MRE below subscribes to a non existing channel yielding an exception in the
Watcher_EventRecordWritten
handler.Expected behavior
The
HResult
from aEventRecordWrittenEventArgs.EventException
should match the win32 error code returned from theEvtNext
function (https://github.com/microsoft/referencesource/blob/5697c29004a34d80acdaf5742d7e699022c64ecd/System.Core/System/Diagnostics/Eventing/Reader/EventLogWatcher.cs#L228).Actual behavior
The
HResult
from aEventRecordWrittenEventArgs.EventException
does not match the actual error message.All
EventRecordWrittenEventArgs.EventException
seem to return the sameHResult
and theEventException
is of the base typeException
so there is no way to different between different errors.Regression?
No response
Known Workarounds
No response
Configuration
.NET 6
Windows 10 21H2 (OS Build 19043.1586)
x64
Other information
No response
The text was updated successfully, but these errors were encountered: