Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Detect Event Viewer Keywords null value
Message
From
10/01/2017 09:24:54
 
 
To
10/01/2017 08:36:21
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
VB 9.0
OS:
Windows 8.1
Network:
Windows Server 2012
Database:
Visual FoxPro
Application:
Web
Miscellaneous
Thread ID:
01646401
Message ID:
01646450
Views:
24
>>Didn't realize you were using System.Diagnostics. The most likely cause of your problem is that you are attempting to read a log entry where the relevant log is not found. Try something like this to test (It's a C# console example but easily converted to VB):
>>            EventLogReader loEventLogReader = new EventLogReader("Application");
>>            EventLogRecord loEventLogRecord = null;
>>
>>            while (true)
>>            {
>>
>>                try
>>                {
>>                    loEventLogRecord = (EventLogRecord)loEventLogReader.ReadEvent();
>>                    if (loEventLogRecord == null)
>>                    {
>>                        Console.WriteLine("End of Log");
>>                        break;
>>                    }
>>
>>                    Int64 result = loEventLogRecord.Keywords ?? 0;
>>                    Console.WriteLine(loEventLogRecord.TimeCreated.ToString()+": "+result.ToString());
>>                    string final = string.Empty;
>>                    foreach (string lcString in loEventLogRecord.KeywordsDisplayNames)
>>                    {
>>                        final += lcString + ",";
>>                    }
>>                    if (final.Length > 0)
>>                    {
>>                        final = final.Substring(0, final.Length - 1);
>>                    }
>>                    Console.WriteLine(final);
>>                }
>>                catch (Exception Ex)
>>                {
>>                    Console.WriteLine("EventLog not found at {0} for {1} ",loEventLogRecord.TimeCreated.ToString(), loEventLogRecord.ProviderName);
>>                }
>>            }
>>            Console.ReadLine();
If you break on the exception you will see that Keywords and KeywordsDisplayNames both throw an exception....
>
>Thanks
>
>The event log, in such situation, is found as I can collect dozen of other properties. So, globalizing all this into a Try/Catch to avoid that situation will probably not change anything.
>
>That specific line of declaration translates to this in VB.Net:
>
>
>Dim result As Int64 = If(loEventLogRecord.Keywords, 0)
>
>
>I am not sure about that syntax. Is it that part of the code you wanted to mention that could resolve the issue?

It will convert a null value to a 0 if that occurs but the real fix is to use the try/catch block to ignore log entries which cannot be resolved. There can be several reasons why that can happen. See:
https://support.microsoft.com/en-us/kb/166902
I guess the EventReader is a bit flaky when that happens - the EventLogRecord is created but some properties cannot be populated because the data can't be found.
AFAIKS ignoring these (or handling them differently) is the only solution.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform