Skip to content

No information about application is recorded when WindowsEventLog class failed to write event log #116178

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

Merged
merged 3 commits into from
Jun 19, 2025

Conversation

pedrobsaila
Copy link
Contributor

Fixes #116022

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label May 31, 2025
@kemats
Copy link

kemats commented Jun 3, 2025

I think it would be more useful for troubleshooting if process name is included in the message as well.

@pedrobsaila
Copy link
Contributor Author

pedrobsaila commented Jun 8, 2025

I think it would be more useful for troubleshooting if process name is included in the message as well.

/// <summary>
/// The application name (source name) to use when writing to the event log.
/// </summary>
[ReadOnly(true)]
[DefaultValue("")]
[SettingsBindable(true)]
public string Source

The source name should be helping partially with that. Passing down the process name requires changing the public interfaces of the library so we can pass down the process id and lookup the process name.

@tarekgh do you see another way to get the process name ?

@tarekgh
Copy link
Member

tarekgh commented Jun 8, 2025

Yes, this will be challenging, especially since remote logging may not always include the process name. Additionally, Windows doesn’t provide this by default, and we should probably avoid implementing it ourselves to stay consistent with the platform's behavior.

@tarekgh
Copy link
Member

tarekgh commented Jun 8, 2025

@pedrobsaila thanks for providing the change!

Could you please add some test for this case in the file https://github.com/dotnet/runtime/blob/main/src/libraries/System.Diagnostics.EventLog/tests/EventLogTests/EventLogTests.cs

Add the test case with the following condition:

private bool static IsNetCoreAndNotElevatedAndSupportsEventLogs => PlatformDetection.IsNetCore && Helpers.NotElevatedAndSupportsEventLogs;

[ConditionalFact(nameof(IsNetCoreAndNotElevatedAndSupportsEventLogs))]

Then you can do something like

new EventLog("Application, ".", "EventSourceNameShouldnotExist").WriteEntry("Some Message");

And validate the thrown exception and the exception message.

I didn't try it so please try to run the new test locally before submitting it.

@tarekgh tarekgh added this to the 10.0.0 milestone Jun 8, 2025
@tarekgh tarekgh self-assigned this Jun 8, 2025
@tarekgh tarekgh added the needs-author-action An issue or pull request that requires more info or actions from the author. label Jun 8, 2025
@tarekgh
Copy link
Member

tarekgh commented Jun 19, 2025

/ba-g the failures are not related, and it is infrastructure specific.

Copy link
Member

@tarekgh tarekgh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @pedrobsaila

@tarekgh tarekgh merged commit 542b947 into dotnet:main Jun 19, 2025
82 of 87 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Diagnostics.EventLog community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No information about application is recorded when WindowsEventLog class failed to write event log
3 participants