c# - Filtering Windows logs using lambda expressions on non-IEnumerable types -


i'm trying , filter windows logs based on criteria, 1 of filter message. message property in eventlog.geteventlogs().entries.message. problem entries eventlogentrycollection , can't run lambda expression (where) on it. tried casting ienumberable (list) type throws exception , says cannot cast. other issue it's read-only property makes practically impossible create new eventlog object , add entries manually. tried was:

list<eventlog> filteredlist = eventlog.geteventlogs().where( x => string.equals(x.logdisplayname, "some value")).where(x => x.entries.where(... 

but entries.where() won't work because it's not ienumberable. i've been thinking alternate solution hours i'm hopeless now. appreciated.

eventlogentrycollection (the type of object returned x.entries in query) implements ienumerable, not generic ienumerable<eventlogentry>. use linq methods have cast each element:

x => x.entries.cast<eventlogentry>().where(... 

cast<t>() accepts ienumerable , returns ienumerable<t>, each element casted requested type, raising classcastexception if fails. since eventlogentry type of object should in collection, safe operation.

(oftype<t>() similar, except omit elements cannot cast requested type rather raising exception. in particular case, observable behavior should identical.)


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -