开发者

Create EventLog Event Source for Standard Users

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开发者_StackOverflow 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.


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.


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜