Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting exception on reading LevelDisplayName property in EventRecord class

I had created a windows application(C#) to read Event log files. When I am trying to read "LevelDisplayName" or "TaskDisplayName" property I get exception "System.Diagnostic.Eventing.Reader.EventLogNotFoundException".

On debugging the code, I found that on first time checking the value shows this exception and again checking the value shows null and my code works fine.

The following line of code first throw the exception(on the line eventRecord.LevelDisplayName) and on checking again shows null value,

string level = string.IsNullOrWhiteSpace(eventRecord.LevelDisplayName) ? GetEventLevelDisplayName(eventRecord.Level.ToString()) : eventRecord.LevelDisplayName;

Where eventRecord is an object of class EventRecord.

Following is the stack trace:

 at System.Diagnostics.Eventing.Reader.EventLogException.Throw(Int32 errorCode)
   at System.Diagnostics.Eventing.Reader.NativeWrapper.EvtOpenProviderMetadata(EventLogHandle session, String ProviderId, String logFilePath, Int32 locale, Int32 flags)
   at System.Diagnostics.Eventing.Reader.ProviderMetadata..ctor(String providerName, EventLogSession session, CultureInfo targetCultureInfo, String logFilePath)
   at System.Diagnostics.Eventing.Reader.ProviderMetadataCachedInformation.GetProviderMetadata(ProviderMetadataId key)
   at System.Diagnostics.Eventing.Reader.ProviderMetadataCachedInformation.GetLevelDisplayName(String ProviderName, EventLogHandle eventHandle)
   at System.Diagnostics.Eventing.Reader.EventLogRecord.get_LevelDisplayName()

Please can someone guide me why exception is thrown and on again checking null value is shown?

like image 954
Lipika Avatar asked Dec 02 '25 09:12

Lipika


1 Answers

I got the same error on my system. And I found a post about the language differences. So I tried it on an English and a Non English OS. The result was it works for me only on English systems. Non English seems to be not supported. So you can try make your own Enum type to get the String results you need or you can use the StandardEventLevel Enum which come with .NET

like image 183
nullIdeas Avatar answered Dec 05 '25 19:12

nullIdeas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!