LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

.Net - Windows Event Viewer

Solved!
Go to solution

Hi, I am trying to read the details if an error is written to the windows event log within the application log. 

 

I have a sample script in C# that I am trying to copy over to LabVIEW. 

 

However, I am getting faults at attempting to do this. 

 

I am looking to pull the date and time, event ID, Message, and Source to perform some comparisons on and log this data to a front panel. However, I am falling at the first hurdle. 

 

Has anyone attempting to read from the Windows event log from LabVIEW before?

 

I've attached an image of the block diagram and also included the VIs - along with the C# code that I am attempting to replicate. 

 

Thanks,

 

Scot07

Download All
0 Kudos
Message 1 of 5
(181 Views)
Solution
Accepted by topic author Scot07

You haven't given a lot of details in terms of what is going on; but a few things stand out to me:

 

  1. The LabVIEW version doesn't match the C# calls (an example is the C# code is casting the EventLog object for BeginInit() and EndInit() calls)
  2. You don't really need the BeginInit() and EndInit() calls and casts in the C# version as you're not hosting the EventLog object in such a way that you need to block it as a control before it is fully configured. So I would remove these.
  3. For a simpler example, you could look at this C# version from MSDN (https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.eventlog.entrywritten?view=netframewo...). You don't need the signalling construct; this is just used to stall the program in order to trigger exit when the event handler is called.
  4. Your VI needs to keep running in order for the callback to be useful (think of it like the Main() method in the example link I sent). Your example top level VI doesn't show this and will just end after that last call.
  5. I assume you'll need to pass data from the callback back to your top-level VI in some manner. What construct you use depends on whether you are only interested in the latest event log or want to see every one. The User Parameter property of the Reg Event Callback node can also be used to pass in any needed reference information for that purpose (eg. Queue reference).
0 Kudos
Message 2 of 5
(138 Views)

One last thing I forgot to add at the end - make sure you close references (including the event callback refnum) when you are finished.

0 Kudos
Message 3 of 5
(123 Views)

Thanks tyk007!

 

I have put together a VI to try and recreate what is in the link. 

 

Couple more questions:

 

  1. The message is only partially being recorded - I am I missing something here?
  2. The callback VI is still running in the background - is there a method to stop this at the end of the VI? I have the unregister for events included in my VI. 

Thanks again,

 

Scot07

Download All
0 Kudos
Message 4 of 5
(111 Views)

The bit where the callback keeps running is this:

 

https://www.ni.com/en-us/support/documentation/bugs/18/labview-2018-known-issues.html#468139_by_Cate...

 

You need to create and add a "GC.Collect" node that runs after your references are closed for it to stop by itself.

0 Kudos
Message 5 of 5
(106 Views)