Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 428289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:39:39+00:00 2026-05-12T19:39:39+00:00

I have a library that I created with some business logic that includes writing

  • 0

I have a library that I created with some business logic that includes writing to a System.Diagnostics.EventLog instance. The library is normally called from a Windows Service application, but now I’m trying to call those same library functions from my ASP.NET MVC application.

I tried this code inside my controller to create the EventLog instance that I pass into the method that needs to write to the log.

Dim log = New EventLog("Application", My.Computer.Name, "MyMVCApp")

The following error is generated when the code within the library method tries to write to the log:

[SecurityException: Requested registry access is not allowed.]
 System.ThrowHelper.ThrowSecurityException(ExceptionResource resource) +51
 Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable) +7462217
 System.Diagnostics.EventLog.CreateEventSource(EventSourceCreationData sourceData) +366
 System.Diagnostics.EventLog.VerifyAndCreateSource(String sourceName, String currentMachineName) +194
 System.Diagnostics.EventLog.WriteEntry(String message, EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData) +205
 System.Diagnostics.EventLog.WriteEntry(String message, EventLogEntryType type) +14

My web app is running as the Network Service user on Windows Server 2003 running IIS 6. Is there something I need to do in order to give the Network Service user access to the registry?

Is there a better way to create an EventLog instance for use in an ASP.NET MVC application? Is there one already created by the framework that I just need to reference?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T19:39:39+00:00Added an answer on May 12, 2026 at 7:39 pm

    From MSDN: “Applications that run using the Network Service identity can write to the event log by using existing event sources, but they cannot create new event sources because of insufficient registry permissions.”

    And…

    “If the Source for the event log associated with the EventLog instance does not exist, a new event source is created.“

    So looks like your event log source doesn’t exist, and it’s trying to create a new event log source using the Network Service User (which requires writing to the registry, so wont work).

    “To enable your ASP.NET application to write to the event log using an event source that does not already exist, you have two options:”

    • Create new event sources at application install time
    • Manually create new event source entry in the registry.

    So, need to create the log outside of the application (you can’t do it programatically with this user. Do it either manually, or create a simple command line app to simplify installation).

    For full details:

    http://msdn.microsoft.com/en-us/library/ms998320.aspx#paght000015_eventlogaccess

    Personally I’d recommend that you don’t alter the net user permissions, but rather create the log source outside of the web app. My preference is in a console app (which will take you about 5mins to write, and which you can also use to prep other machines). Start a new console app in VS.NET, and add the code to create the log sources. An example:

    http://www.dotnetspider.com/resources/23593-Create-Event-log-VB-NET.aspx

    Then just run the console app from the cmd line, when logged in with appropriate permissions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a Library Project which I import into another project. In that
I have a library that I would like to license and distribute. I know
Whenever I have a library that use across different websites/ applications I've always just
I have a C++ library that provides various classes for managing data. I have
I have a shared library that I wish to link an executable against using
We have a C++ library that we provide to several different clients. Recently we
I have a java library that I am accessing in VB.NET via COM. The
I have a third party library that internally constructs and uses the SqlConnection class.
I have an existing library (JPhysX) that is a Java wrapper for a native
I have this small code library that I'm considering releasing into Open Source. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.