Has anyone found an easy way to retrieve messages from the Windows Eventlog (Application log) in to Navision ?
I was thinking of using an existing Windows automation or a freeware/shareware component but I can't find out which one to use.
What I want is to make a codeunit able to import all Windows application log entries in to a Navision table (or set a filter so that only application log entries related to the active NAS is being imported).
The Eventlog controls I have found are quite expensive - is it not possible to do this with native Microsoft components or has any one in here created an automation/ocx for this purpose ?
0
Comments
Try to find a good code sample for event log operations (I used to have a brilliant article about this but my link doesn't work anymore) for .NET like VB or C#. You can usually find the dll in the automation list inside the C/AL editor. Then it's just a matter of getting it to work in NAV.
RIS Plus, LLC
but that is exactly my problem: I can't find a suitable dll or ocx.
The only ones I can find are fancy 200 - 400 $ components and the only thing I want to do is to read the eventlog.
Does anyone else have a link or referance to component with a simple code example ?
Here's the Dynamics Nav Code
Download:: Source, Compiled And Setup
Please post bugs here..
cSharp Code:
Rvduuren
I have used the link from Luc because this was based on standard MS components only (I did search before posting this topic but didn't find the link in the search result).
With the solution from ara3n (the link from Luc) I can read the eventlog from a codeunit (a create(WindowsShell) was missing in the example but I figured that out).
The example shows how to read the latest entry in the log but I want to read them all and insert them into a table.
This should be possible by changing the /r parameter but if I increase this to a value larger than 7 I get an error message in Navision saying "The length of the text string exceeds the size of the string buffer."
This works (reading 1 eventlog entry):
IF EventRec.FIND('+') THEN
NextEvent := EventRec."Event No." ELSE
NextEvent := EventRec."Event No.";
NextEvent := NextEvent + 1;
CREATE(WindowShell);
WindowShell.CurrentDirectory(ENVIRON('windir') + '\system32\');
txtCommand := 'cscript eventquery.vbs /L Application /FI "Type eq Error" /V /r 1 /FO "LIST"';
WSHExec := WindowShell.Exec(txtCommand);
WSHTextStream := WSHExec.StdOut;
NextEventLine := 0;
REPEAT
EventRec.INIT;
NextEventLine := NextEventLine + 1;
EventRec."Event No." := NextEvent;
EventRec."Event Line No." := NextEventLine;
EventRec.Text := COPYSTR(WSHTextStream.ReadLine,1,250);
EventRec.INSERT;
UNTIL WSHTextStream.AtEndOfStream;
This doesn't work (reading more than 7 entries):
txtCommand := 'cscript eventquery.vbs /L Application /FI "Type eq Error" /V /r 8 /FO "LIST"';
Can anybody help or suggest a workaround for this ?
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
If I could only delete the message after having read it that would do the trick, but the script is for reading only
1) At which line stop the debugger when you try to read more than 8 events?
2) Try to compare the output of the script when called from command line. It seems that some line from the output is longer than your destination.
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
EventRec.Text := COPYSTR(WSHTextStream.ReadLine,1,250);
..which is exactly why I'm using the COPYSTR command (and yes I have checked that the Text field is defined as text with the length 250).
I seems that it is WSHTextStream.ReadLine which can't read long strings.
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!