EventLog.WriteEntry到远程机器 [英] EventLog.WriteEntry to Remote Machine

查看:82
本文介绍了EventLog.WriteEntry到远程机器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下午好,



想知道是否有人可以帮我这个:



我是什么尝试实现的是将完整的事件日志条目(包括日志类型等)写入Win2k8服务器上的远程事件日志。我已经为正确的SID设置了SDDL,因此权限不是问题。



我的问题是如果我使用基本 EventLog.WriteEntry 消息它工作正常,远程机器接收请求但是当我尝试输入完整条目时它会产生一个警告:

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



随后不会填充远程计算机上的事件日志。



登录本地计算机只是一个选项,只是把它们放在TFTP图像上,这些图像在重启设备时被重置,因此会丢失任何历史记录。



这个工作正常:


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:

MyEvtLog.WriteEntry(Message)





到目前为止我的代码:





My code so far:

    '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





当然会欣赏有关将完整的事件日志条目写入远程计算机的一些信息,因为目前这不起作用,但我需要能够确定错误或警告。



谢谢

dave



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

推荐答案

您的代码正在呼唤:

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



查看变量类型,这是 WriteEntry(String,String,EventLogEntryType,Int32) [ ^ ] overload,这是一个静态共享)方法。



您可能打算调用 WriteEntry(String,EventLogEntryType) ,Int32) [ ^ ]重载,这是一个实例方法。您不需要再次传递源,因为您已经将它传递给 EventLog 构造函数。


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.

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


这篇关于EventLog.WriteEntry到远程机器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆