为标准用户创建EventLog事件源

发布于 2024-12-04 18:38:58 字数 1002 浏览 2 评论 0原文

我的应用程序使用事件日志来记录异常和信息消息,但是当以访问权限有限的标准用户身份登录时,我收到异常:

未找到源,但无法获取部分或全部事件日志 搜索过。无法访问的日志:安全性

我了解在我写入的日志(应用程序)中找不到事件源,并且应用程序正在尝试创建事件源,但在注册之前需要检查所有日志以确保事件源尚未使用。

我的问题是我应该如何创建可供标准用户使用的事件源?该应用程序将在公司网络上运行,我们将所有用户锁定到最低要求的权限。

我尝试通过创建一个新的 VS2008 类文件项目来解决此问题,该项目将以管理员用户身份运行并注册 EventSource,但这并没有解决该错误。以下是我的班级。

Imports System.Diagnostics
Imports System.Configuration.Install
Imports System.ComponentModel

<RunInstaller(True)> _
Public Class InstallEventLog
    Inherits Installer
    Private myEventLogInstaller As EventLogInstaller
    Public Const EventSource As String = "My Application Here"

    Public Sub New()
        myEventLogInstaller = New EventLogInstaller
        myEventLogInstaller.Source = EventSource
        myEventLogInstaller.Log = "Application"
        Installers.Add(myEventLogInstaller)
    End Sub
End Class

然后,我向我的解决方案添加了一个安装项目,该项目具有类项目的主要输出,安装程序会安装,但是当再次运行我的应用程序时,它会失败,并显示上面相同的错误消息。

My applicaiton makes use of the Event Log to log exceptions and Informational messages, however when logged in as a Standard User who has limited access, I am receiving the Exception:

The source was not found, but some or all event logs could not be
searched. Inaccessible Logs: Security

I understand that the Event Source cannot be found in the log I am writting to (Application) and the application is attempting to create the Event Source but before it can be registered all Logs need to be reviewed to make sure the Event Source isn't already in use.

My question is how should I go about creating an Event Source that can be used by Standard Users? The application will be operating on a corporate network whereby we lock down all users to the least required privellages.

I have attempted to resolve this by creating a new VS2008 Class File project that will be ran as an Administrator User that will register the EventSource, however this hasn't resolved the error. The following is my Class.

Imports System.Diagnostics
Imports System.Configuration.Install
Imports System.ComponentModel

<RunInstaller(True)> _
Public Class InstallEventLog
    Inherits Installer
    Private myEventLogInstaller As EventLogInstaller
    Public Const EventSource As String = "My Application Here"

    Public Sub New()
        myEventLogInstaller = New EventLogInstaller
        myEventLogInstaller.Source = EventSource
        myEventLogInstaller.Log = "Application"
        Installers.Add(myEventLogInstaller)
    End Sub
End Class

I then added to my Solution a setup Project which has the Primary Output of the Class Project, the setup installs however when running my application again it fails with the same error message above.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

咿呀咿呀哟 2024-12-11 18:38:58

根据用户“登录”的方式,不可能使用“应用程序”日志...您绝对应该尝试创建自己的日志(不仅仅是 LogSource!)并看看是否有效...

恕我直言,最好的方法要解决此问题,请要求管理员通过组策略为您创建 EventSource - 这将确保正确的权限等。

Depending on how "logged down" your users are the use of the "Application" Log is not possible... you should definitely try creating your own Log (not only LogSource!) and see if that works...

IMHO the best way to solve this would be aske the administrators to create the EventSource for you via a Group Policy - this would ensure the correct rights etc.

绅刃 2024-12-11 18:38:58

实际上,我在我的主 exe 项目中添加了一个特殊的“类型”System.Configuration.Install.Installer 类,它似乎在应用程序安装过程中由 .msi 成功运行(请参阅装饰.. 这很重要) )。现在,请注意,即使这个特殊的安装程序类成功自动注册事件日志源,如果最终用户双击 .msi 来执行安装 - 在安装过程中的某个时刻 - 屏幕会变黑并出现提示显示管理员凭据。因此,无论如何都需要提升权限。

这是我的类,它只是我的 Windows Forms .exe 项目中的另一个类:

Imports System.ComponentModel
Imports System.Configuration.Install

<RunInstaller(True)>     
Public Class CoolAppEventLogInstaller
  Inherits System.Configuration.Install.Installer

  Private myEventLogInstaller As EventLogInstaller

  Public Sub New()
    'This call is required by the Component Designer.
    InitializeComponent()

    'Add initialization code after the call to InitializeComponent

    ' Create an instance of an EventLogInstaller.
    myEventLogInstaller = New EventLogInstaller()

    ' Set the source name of the event log.
    myEventLogInstaller.Source = "MyCompany Cool App"


    ' Add myEventLogInstaller to the Installer collection.
    Installers.Add(myEventLogInstaller)
  End Sub 'New

    Public Shared Sub Main()
    End Sub 'Main


End Class

就其价值而言,上述代码与我的 app.config 中的 EventLog 片段结合使用

    <sharedListeners>
      <add name="EventLog" initializeData="MyCompany Cool App" type="System.Diagnostics.EventLogTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
    </sharedListeners>

I actually added a special 'type of' System.Configuration.Install.Installer class into my main exe project which seems to be successfully run by the .msi during application installation (see decoration.. that is important). Now, mind you, even though this special installer class successfully registers the event log source automatically, if the end-user is double-clicking the .msi to perform the installation - at some point during the install - the screen goes dark and a prompt for admin credentials is displayed.. so, elevated permissions are required regardless.

Here's my class that, once again, is just another class sitting in my Windows Forms .exe project:

Imports System.ComponentModel
Imports System.Configuration.Install

<RunInstaller(True)>     
Public Class CoolAppEventLogInstaller
  Inherits System.Configuration.Install.Installer

  Private myEventLogInstaller As EventLogInstaller

  Public Sub New()
    'This call is required by the Component Designer.
    InitializeComponent()

    'Add initialization code after the call to InitializeComponent

    ' Create an instance of an EventLogInstaller.
    myEventLogInstaller = New EventLogInstaller()

    ' Set the source name of the event log.
    myEventLogInstaller.Source = "MyCompany Cool App"


    ' Add myEventLogInstaller to the Installer collection.
    Installers.Add(myEventLogInstaller)
  End Sub 'New

    Public Shared Sub Main()
    End Sub 'Main


End Class

For what it's worth, the above code works in conjunction with an EventLog snippet in my app.config

    <sharedListeners>
      <add name="EventLog" initializeData="MyCompany Cool App" type="System.Diagnostics.EventLogTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
    </sharedListeners>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文