diff --git a/changelogs/fragments/59503-fix-recursive-csharp-logging.yml b/changelogs/fragments/59503-fix-recursive-csharp-logging.yml new file mode 100644 index 00000000000..3c746029cd1 --- /dev/null +++ b/changelogs/fragments/59503-fix-recursive-csharp-logging.yml @@ -0,0 +1,2 @@ +bugfixes: + - ansible.basics - fix core C# recursive call when logging fails (e.g. if insufficient permissions are held) (https://github.com/ansible/ansible/pull/59503) diff --git a/lib/ansible/module_utils/csharp/Ansible.Basic.cs b/lib/ansible/module_utils/csharp/Ansible.Basic.cs index 6a7d03fdcb5..d1011c860ff 100644 --- a/lib/ansible/module_utils/csharp/Ansible.Basic.cs +++ b/lib/ansible/module_utils/csharp/Ansible.Basic.cs @@ -304,7 +304,8 @@ namespace Ansible.Basic } catch (System.Security.SecurityException) { - Warn(String.Format("Access error when creating EventLog source {0}, logging to the Application source instead", logSource)); + // Cannot call Warn as that calls LogEvent and we get stuck in a loop + warnings.Add(String.Format("Access error when creating EventLog source {0}, logging to the Application source instead", logSource)); logSource = "Application"; } }