Retrieving Eventlog messages in Navision ?

ehs
Member Posts: 34
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 ?
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
-
I have not done this particular thing, but have programmed many other types of automation just like this, and I have programmed event log operations in other languages.
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.0 -
Thanks DenSter,
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 ?0 -
Have a look at this topic: Read EventLogNo support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)0
-
I've created some C# code, and it results a xml file of the Event Log..
Here's the Dynamics Nav CodeGLOBALS EventLog - Automation - 'XMLEventLog'.ReadEventLog ----- create(EventLog); EventLog.GetEventLog('Application', 'myhost', 'c:\xmlfile.xml'); // Application/System/... clear(EventLog);
Download:: Source, Compiled And Setup
Please post bugs here..
cSharp Code:using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; using System.Data; using System.Xml; using System.Diagnostics; namespace XMLEventLog { [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)] public interface IReadEventLog { void GetEventLog(string LogEventType, string HostName, string XmlFileName); } [ClassInterface(ClassInterfaceType.None)] public class ReadEventLog : IReadEventLog { public void GetEventLog(string LogEventType, string HostName, string XmlFileName) { DataTable dataTable = new DataTable("Log"); dataTable.Columns.Add("Index", Type.GetType("System.Int32")); dataTable.Columns.Add("EntryType", Type.GetType("System.String")); dataTable.Columns.Add("TimeGenerated", Type.GetType("System.DateTime")); dataTable.Columns.Add("Source", Type.GetType("System.String")); dataTable.Columns.Add("UserName", Type.GetType("System.String")); dataTable.Columns.Add("MachineName", Type.GetType("System.String")); dataTable.Columns.Add("Message", Type.GetType("System.String")); DataRow dataRow; EventLog eventLog = new EventLog(LogEventType, HostName); if (eventLog.Entries.Count > 0) { foreach (EventLogEntry eventLogEntry in eventLog.Entries) { dataRow = dataTable.NewRow(); dataRow["Index"] = eventLogEntry.Index; dataRow["EntryType"] = eventLogEntry.EntryType; dataRow["TimeGenerated"] = eventLogEntry.TimeGenerated; dataRow["Source"] = eventLogEntry.Source; dataRow["UserName"] = eventLogEntry.UserName; dataRow["MachineName"] = eventLogEntry.MachineName; dataRow["Message"] = eventLogEntry.Message; dataTable.Rows.Add(dataRow); } DataSet dataSet = new DataSet(LogEventType); dataSet.Tables.Add(dataTable); XmlDataDocument xmlDatDoc = new XmlDataDocument(dataSet); xmlDatDoc.Save(XmlFileName); } } } }
Met vriendelijke groet, best regards,
Rvduuren0 -
Thank you Luc and 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 ?0 -
try to read them one by one using the N1-N2 syntax for parameter /r. See http://technet2.microsoft.com/windowsse ... x?mfr=true for more help.0
-
I have already tried that to with the same result/error message.
If I could only delete the message after having read it that would do the trick, but the script is for reading only0 -
I have one info for you: the script doesn't exists under Vista... 8) (but you can use the "wevtutil" to query the event log under Vista).
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.0 -
It stops with the error at the following line :
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.0 -
Than you need to use Read(Chars) instead ReadLine to limit how much chars you want to read. You can read the text char by char and process them into string with max length 250.0
-
[Topic moved from Navision forum to Navision Tips & Tricks forum]Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions