Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Detect Event Viewer Keywords null value
Message
From
10/01/2017 23:28:30
 
 
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:
01646491
Views:
27
>>>>>Don't understand your question. Firstly, you are casting to loEventLogRecord but not using it in subsequent code. And what is the value of loEventRecord and loEventRecord.Keywords when the if statement executes ?
>>>>
>>>>Here is more information.
>>>>
>>>>The initialization of various event records is done here:
>>>>
>>>>
>>>>' Initialization
>>>>loEventRecord = loEventLogReader.ReadEvent()
>>>>
>>>>' For each record
>>>>While Not loEventRecord Is Nothing
>>>>
>>>>   ' Cast the EventRecord object as an EventLogRecord object to access the EventLogRecord class properties
>>>>   loEventLogRecord = CType(loEventRecord, EventLogRecord)
>>>>
>>>>
>>>>Most of the event log record properties are accessed by using loEventRecord. However, when we have a property which contains several items, we have to use it like this:
>>>>
>>>>
>>>>' Reset the values
>>>>lcFinal = ""
>>>>
>>>>' For each keyword
>>>>For Each lcString In loEventLogRecord.KeywordsDisplayNames
>>>>
>>>>   ' If we have a string
>>>>   If lcFinal.Length > 0 Then
>>>>      lcFinal = lcFinal + ", "
>>>>   End If
>>>>
>>>>   lcFinal = lcFinal + lcString
>>>>Next
>>>>
>>>>loInsertRow.ParameterAdd("KeywordDisplayName", lcFinal)
>>>>
>>>>
>>>>Properties such as Level, Id, ProviderName, FormatDescription, just to name a few, are accessed directly from loEventRecord. But, properties KeywordDisplayNames and Properties need to be accessed from loEventLogRecord.
>>>>
>>>>The event log record contains various structures. Also, some of them can return null. Version, for example, can be detected for null by using is IS NOTHING comparism. But, Keywords is not supporting that. So, if I just replace that as is in the table field, into which I transfer that into a SQL Server table format, I will end up with null. And, I don't want null. I need to put a 0 in there, as Keywords, which represents a Long value, when it is null, need to be represented as 0 in my table.
>>>>
>>>>I think the problem comes from the fact that this is a Long. There has to be a way to detect a null value in such circumstance.
>>>
>>>A .Net long (Int64) is never null (unless you use a nullable type) - it's a value reference. Are you confusing it with the DBType (which can be nullable)
>>
>>Seems EventLogRecord.Keywords is nullable https://msdn.microsoft.com/en-us/library/system.diagnostics.eventing.reader.eventlogrecord.keywords(v=vs.110).aspx
>
>Thanks. I didn't realize that Michel was using System.Diagnostics. See my reply to him - I ran some test code on a Application log and discovered that some entries were not found (wrong path info probably) and when that happens accessing some of the EventLogRecord properties (KeywordsDisplayNames, LevelDisplayName, OpCodeDisplayName and TaskDisplayName) throws a EventLogNotFoundException. Can't see any solution other than trapping for that in a try block :-{

There must be a bug in the code that converts the entries to C# class instances Hence all the trouble
Gregory
Previous
Reply
Map
View

Click here to load this message in the networking platform