LogError() in KfxReleaseScript

172 Views Asked by At

When creating a Kofax Release Script errors might occur. Currently I show the Error Messageboxes in my catch statement.

public KfxReturnValue OpenScript(){
    try{
        // ...
        return KfxReturnValue.KFX_REL_SUCCESS;
    }catch (Exception e){
        // Show Error Messagebox
        return KfxReturnValue.KFX_REL_ERROR;
    }
}

public KfxReturnValue ReleaseDoc(){
    try{
        // ... 
        return KfxReturnValue.KFX_REL_SUCCESS;
    }catch (Exception e){
        // Show Error Messagebox
        return KfxReturnValue.KFX_REL_ERROR;
    }
}

public KfxReturnValue CloseScript(){
    try{
        GC.Collect();
        GC.WaitForPendingFinalizers();
        return KfxReturnValue.KFX_REL_SUCCESS;
    }catch (Exception e){
        // Show Error Messagebox
        return KfxReturnValue.KFX_REL_ERROR;
    }
}

The ReleaseData object has a method called LogError. This method does the following

Logs an error in the Kofax Capture Error Log. A new error log is created for each month and the file name indicates the month and year. For example, the error log for January 2008 is ERR_0108.txt.

It takes the following parameters

Err1 as long 
Err2 as long 
Err3 as long 
ErrorMessage as string
CodeModule as string 
LineNumber as long

None of these parameters are optional. I can't find anything about these parameters in the docs so what do I need to get passed in there? (ErrorMessage is obvious, CodeModule might be Kofax Capture Export Connector)

1

There are 1 best solutions below

0
On

While the parameters aren't optional, you can just use any value (which you already figured out). In addition, here's how to log the whole stack along with the line number, which will help identifying the root cause of an issue. Please note that you will have to include the pdb file along with the binaries.

private void LogCaptureError(Exception e)
{
    // make sure to provide the pdb file, otherwise we can not access the line number
    DocumentData.LogError(0, 0, 0, 
      e.ToString(), 
      e.Source, 
      (new StackTrace(e, true).GetFrame(0).GetFileLineNumber())
    );            
}