Windows Event Log: The description for Event ID ??? from source Microsoft Dynamics AX cannot be found

When maintaining Dynamics AX installations, it is necessarry to have a look into the windows event log from time to time.
I often get greeted by messages similar to the following as:

The description for Event ID 193 from source Microsoft Dynamics AX cannot be found. Either the component that raises this event is not installed on your local computer or the installation is corrupted. You can install or repair the component on the local computer.

If the event originated on another computer, the display information had to be saved with the event.

AX Event log error source missing

I am using a PowerShell script to get the message text from errors and with this scenario I cannot obtain any useful text right now.

Solution first

For people only wanting the solution real quick, here it is:

  1. Run RegEdit
  2. Navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog\Application
  3. Add Key Microsoft Dynamics AX
  4. Add String value EventMessageFile
  5. Set the value to C:\Program Files (x86)\Microsoft Dynamics AX\60\\Client\Bin\Ax32.exe or whereever your AX Client is installed.
  6. Refresh Event log (F5 or close and open again)

Result:
Fix key

Outcome:
Fixed result

Background

The Event Log basically works with message files so the applications do not write directly in it. You can get some more details in a very detailed Blog post here, thanks for the effort!

So the reason is a missing message file directive and that makes it fall back to another (wrong) one.

Fast lane: PowerShell script for repair

To save you event more time and to be able to check and repair multiple environments, I wrote a PowerShell script for that:

#
# AXEventLogFix by Robin Kretzschmar 11.10.2016
#
$clientInstallPath = "C:\Program Files (x86)\Microsoft Dynamics AX\60\\Client\Bin\Ax32.exe"
Function CheckKeyExists() {
    try
    {
        Set-Location HKLM:\
        gci -Path '.\SYSTEM\CurrentControlSet\Services\EventLog\Application\Microsoft Dynamics AX' -ErrorAction Stop
    }
    catch [System.Management.Automation.ItemNotFoundException]
    {
        # Key does not exist.
        return $false
    }
    catch [System.Security.SecurityException]
    {
        Write-Host "Security Exception!"
    }
    catch #all
    {
        Write-Host "There was an error while checking."
        Write-Host "$StackTrace"
    }
    return $true
}

Function CheckKeyValue() {
    try
    {
        Set-Location HKLM:\
        $prop = (Get-ItemProperty -Path '.\SYSTEM\CurrentControlSet\Services\EventLog\Application\Microsoft Dynamics AX' -Name 'EventMessageFile' -ErrorAction Stop).EventMessageFile
        If ($prop -eq $clientInstallPath) {
            Write-Host "value set / correct to path: $prop"
        } Else {
            Write-Host "Value has wrong path: $prop"
            Write-Host "Setting correct path"
            CorrectKeyValue
        }
    }
    catch [System.Management.Automation.PSArgumentException]
    {
        Write-Host "Value / Subkey not existing, need to create it"
        CreateValueKey
    }
    catch #all
    {
        Write-Host "Error checking the value of the key!"
        $Error[3] | Select –Property *
        return $false
    }
    return $true
}

Function CorrectKeyValue() {
    try
    {
        Set-Location HKLM:\
        Write-Host "Setting value to $clientInstallPath"
        Set-ItemProperty -Path '.\SYSTEM\CurrentControlSet\Services\EventLog\Application\Microsoft Dynamics AX' -Name 'EventMessageFile' -Value $clientInstallPath -ErrorAction Stop | Out-Null
    }
    catch #all
    {
        Write-Host "Error while changing value for key!"
        $Error[4] | Select –Property *
        return $false
    }
    return $true
}

Function CreateValueKey() {
    try
    {
        Set-Location HKLM:\
            Write-Host "Creating sub-key 'EventMessageFile'"
            New-ItemProperty -Path '.\SYSTEM\CurrentControlSet\Services\EventLog\Application\Microsoft Dynamics AX' -Name 'EventMessageFile' -PropertyType String -Value $clientInstallPath -ErrorAction Stop | Out-Null
    }
    catch #all
    {
        Write-Host "Error while checking / creating value for key!"
        $Error[4] | Select –Property *
        return $false
    }
    return $true
}

Function CreateKey() {
    try
    {
        Set-Location HKLM:\
        New-Item -Path '.\SYSTEM\CurrentControlSet\Services\EventLog\Application' -Name 'Microsoft Dynamics AX' -ErrorAction Stop
        Write-Host "Key created"

    }
    catch #all
    {
        Write-Host "Error creating the new key! Did you run the script with administrative privileges?"
        $Error[4] | Select –Property *
        return $false
    }
    return $true
}

$keyExisting = CheckKeyExists
If ($keyExisting -eq $false) {
    $res = CreateKey
    if ($res -eq $true) {
        $res = CheckKeyValue
    }
} else {
    Write-Host "Key exists (OK)"
    $res = CheckKeyValue
}

Download Script: AXEventLogFix.ps1

Robin

Software Engineer / Application Developer

Subscribe to robsCode

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!