Click here to Skip to main content
15,868,039 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good Afternoon,

Wondering if someone can help me with this:

What i am trying to achieve is writing a full event log entry including log type and so on to a remote event log on Win2k8 server. I have already setup the SDDL for this for the correct SID so permissions are not an issue.

My issue here is that if i use the basic EventLog.WriteEntry message it works fine and the remote machine receives the request however when i try and enter a full entry it produces a warning of:
Access of shared member, constant member, enum member or nested type through an instance; qualifying expression will not be evaluated

Which subsequently does not populate the event log on the remote machine.

Logging on the local machine is just not an option simply put they are wokring on TFTP images which are reset upon restart of the device and thus will lose any history.

This Works Fine:
VB
MyEvtLog.WriteEntry(Message)


My code so far:

VB
    'Event Logs
    Private MyEvtLog As EventLog
    Dim Source As String = "My Product"
    Dim Log As String = "Company Software"
    Dim eMachine As String = "MyMachineName.Domain.Local"

    Enum LoggingSeverity
        Informational = 1
        Warning = 2
        Severe = 3
        Critical = 4
    End Enum
    Sub New()
        Try
            'Setup Event Log on Remote Machine
            MyEvtLog = New EventLog(Log, eMachine, Source)
        Catch ex As Exception
            'Cannot Create file
        End Try
    End Sub

Private Sub Logging_LoggingRequest(Severity As LoggingSeverity, DateTime As String, Message As String, ByVal Document As String, ByVal Routine As String) 
        Try
            'Structure Data Format
            Dim LogDataEntry As String = 
    "<ComputerInfo>
        <Username>{0}</Username>
        <Computer>{1}</Computer>
        <Domain>{2}</Domain>
    </ComputerInfo>
    <ErrorDetails>
        <Severity>{3}</Severity>
        <Timestamp>{4}</Timestamp>
        <Document>{5}</Document>
        <Routine>{6}</Routine>
        <Message>{7}</Message>
    </ErrorDetails>"

            'Format the Data
            LogDataEntry = String.Format(LogDataEntry, Environment.UserName, Environment.MachineName, Environment.UserDomainName, Severity, DateTime, Document, Routine, Message)

            Select Case Severity
                Case LoggingSeverity.Informational
                    MyEvtLog.WriteEntry(Source, LogDataEntry, EventLogEntryType.Information, 0)
                Case LoggingSeverity.Warning
                    MyEvtLog.WriteEntry(Source, LogDataEntry, EventLogEntryType.Warning, 0)
                Case LoggingSeverity.Severe
                    MyEvtLog.WriteEntry(Source, LogDataEntry, EventLogEntryType.FailureAudit, 0)
                Case LoggingSeverity.Critical
                    MyEvtLog.WriteEntry(Source, LogDataEntry, EventLogEntryType.Error, 0)
            End Select
        End Try
    End Sub


Certainly would appreciate some info on writing a full event log entry to a remote machine, as currently this doesnt work but i need to be able to determine errors or warnings.

Thanks
dave
Posted
Updated 21-Apr-15 5:19am
v3
Comments
Richard Deeming 21-Apr-15 11:17am    
You've created an EventLog variable called MyEvtLog, but you're never using it; instead, you're calling the WriteEntry method on PrevOpsEvt, which isn't shown.
Dev O'Connor 21-Apr-15 11:21am    
Hi Richard,

Apologies, i stripped out sensetive information but missed that one, i have updated it now with MyEvtLog

I understand its a shared member and cannot be used as such however my issue is here, is i want to be able to write that full event log entry... but to a remote machine not my local machine but if i use the 'EventLog' class it results in writing to my local event log which is what i need to avoid.

1 solution

Your code is calling:
VB.NET
MyEvtLog.WriteEntry(Source, LogDataEntry, EventLogEntryType.Information, 0)

Looking at the variable types, that's the WriteEntry(String, String, EventLogEntryType, Int32)[^] overload, which is a static (Shared) method.

You probably meant to call the WriteEntry(String, EventLogEntryType, Int32)[^] overload, which is an instance method. You don't need to pass the source again, as you've already passed it to the EventLog constructor.
VB.NET
Select Case Severity
    Case LoggingSeverity.Informational
        MyEvtLog.WriteEntry(LogDataEntry, EventLogEntryType.Information, 0)
    Case LoggingSeverity.Warning
        MyEvtLog.WriteEntry(LogDataEntry, EventLogEntryType.Warning, 0)
    Case LoggingSeverity.Severe
        MyEvtLog.WriteEntry(LogDataEntry, EventLogEntryType.FailureAudit, 0)
    Case LoggingSeverity.Critical
        MyEvtLog.WriteEntry(LogDataEntry, EventLogEntryType.Error, 0)
End Select
 
Share this answer
 
Comments
Dev O'Connor 21-Apr-15 14:41pm    
Of course!, Didnt think to check the other methods attached to WriteEntry.

Appreciate it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900