I have a Remote Desktop Gateway on a Windows Server 2022. Here the Windows service, Remote Desktop Gateway, kept crashing and users received the error code 0x300000d when trying to connect. Inspecting the event log on the server revealed this related error:
svchost (1976,R,98) SoftwareUsageMetrics-Api: An attempt to open the file "C:\Windows\system32\LogFiles\Sum\Api.chk" for read / write access failed with system error 5 (0x00000005): "Access is denied. ".
Granting Modify access to the NETWORK SERVICE on the folder C:\Windows\system32\LogFiles\Sum resolved the issue. The RDG service now runs without crashing unexpectedly.