473,666 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Error Writing to Event Log

I am trying to write to the errorlog and I am getting the error

Cannot open log for source 'Application'. You may not have write access.

This is the code:

Dim Logevent As New EventLog("Appli cation")
Logevent.Source = "Applicatio n"

Logevent.WriteE ntry("Log In Error ", EventLogEntryTy pe.Error)

The error is in the WriteEntry .

Thank you
--
Jerry
Aug 11 '06 #1
9 10996
More information to the above post.
I am using ASP.Net. Site is running in IIS 6.0 on Windows 2003 Server. code
is in a aspx page. app is running in a application pool with the idenity of
NETWORK SERVICE.
--
Jerry
"Jerry C" wrote:
I am trying to write to the errorlog and I am getting the error

Cannot open log for source 'Application'. You may not have write access.

This is the code:

Dim Logevent As New EventLog("Appli cation")
Logevent.Source = "Applicatio n"

Logevent.WriteE ntry("Log In Error ", EventLogEntryTy pe.Error)

The error is in the WriteEntry .

Thank you
--
Jerry
Aug 11 '06 #2
Hello Jerry,

try to use just
Dim Logevent As New EventLog()

JCI am trying to write to the errorlog and I am getting the error
JC>
JCCannot open log for source 'Application'. You may not have write
JCaccess.
JC>
JCThis is the code:
JC>
JCDim Logevent As New EventLog("Appli cation")
JCLogevent.Sour ce = "Applicatio n"
JCLogevent.Writ eEntry("Log In Error ", EventLogEntryTy pe.Error)
JC>
JCThe error is in the WriteEntry .
JC>
JCThank you
JC>
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Aug 11 '06 #3
Thanks for the reply.
I tried the line of code and I am still having the same problem.

Any help is appreciated
--
Jerry
"Michael Nemtsev" wrote:
Hello Jerry,

try to use just
Dim Logevent As New EventLog()

JCI am trying to write to the errorlog and I am getting the error
JC>
JCCannot open log for source 'Application'. You may not have write
JCaccess.
JC>
JCThis is the code:
JC>
JCDim Logevent As New EventLog("Appli cation")
JCLogevent.Sour ce = "Applicatio n"
JCLogevent.Writ eEntry("Log In Error ", EventLogEntryTy pe.Error)
JC>
JCThe error is in the WriteEntry .
JC>
JCThank you
JC>
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Aug 11 '06 #4
Hello Jerry,

Then u really need to grand/impersonate rights

See
http://www.c-sharpcorner.com/Code/20...ngInASPNet.asp
http://support.microsoft.com/default...;EN-US;Q329291
http://groups.google.com/groups/sear...y+write+access

JCThanks for the reply. I tried the line of code and I am still having
JCthe same problem.
JC>
JCAny help is appreciated
JC>
JC"Michael Nemtsev" wrote:
JC>
>Hello Jerry,

try to use just Dim Logevent As New EventLog()

JCI am trying to write to the errorlog and I am getting the error
JC>
JCCannot open log for source 'Application'. You may not have write
JCaccess.
JC>
JCThis is the code:
JC>
JCDim Logevent As New EventLog("Appli cation")
JCLogevent.Sou rce = "Applicatio n"
JCLogevent.Wri teEntry("Log In Error ", EventLogEntryTy pe.Error)
JC>
JCThe error is in the WriteEntry .
JC>
JCThank you
JC>
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour
"At times one remains faithful to a cause only because its opponents
do not cease to be insipid." (c) Friedrich Nietzsche
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Aug 11 '06 #5
Hi Jerry,

Are you using Asp.net1.1 or 2.0? I have tried to copy your provided code
snippet in a Asp.net1.1 project Page_Load event(my test machine is Win2003
SP1 with VS.net2003 and VS2005 installed). The project's directory is using
Asp.net1.1 and running under default application pool with identity
NetworkService acount. However, the code runs well in the project both
under debugger and without debugger.

Can you provide the detailed information regarding this error? What is the
exception type of this error? You'd better provide the complete call stack
of this error. This will help us to identify if this error is a .Net code
access security exception or native Win32 eventlog access control
exception.

I will wait for your further information, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

Aug 14 '06 #6
Thank you for your replys.
I have tryed to set the permissions in the registry for this event log
"Applicatio n" and this soruce "Applicatio n" and I am still getting the error.
(Reboot also). I also created a new entry manually and still get the error.

Here is the error

[Win32Exception (0x80004005): Access is denied]

[InvalidOperatio nException: Cannot open log for source 'Application'. You
may not have write access.]
System.Diagnost ics.EventLog.Op enForWrite(Stri ng currentMachineN ame) +719543
System.Diagnost ics.EventLog.In ternalWriteEven t(UInt32 eventID, UInt16
category, EventLogEntryTy pe type, String[] strings, Byte[] rawData, String
currentMachineN ame) +206
System.Diagnost ics.EventLog.Wr iteEntry(String message, EventLogEntryTy pe
type, Int32 eventID, Int16 category, Byte[] rawData) +269
System.Diagnost ics.EventLog.Wr iteEntry(String message, EventLogEntryTy pe
type) +14
LoginV6.Page_Lo ad(Object sender, EventArgs e) in
c:\inetpub\wwwr oot\ContentDepo t\LoginV6.aspx. vb:218
System.Web.UI.C ontrol.OnLoad(E ventArgs e) +99
System.Web.UI.C ontrol.LoadRecu rsive() +47
System.Web.UI.P age.ProcessRequ estMain(Boolean
includeStagesBe foreAsyncPoint, Boolean includeStagesAf terAsyncPoint) +1061
Thank you,
--
Jerry
""Jeffrey Tan[MSFT]"" wrote:
Hi Jerry,

Are you using Asp.net1.1 or 2.0? I have tried to copy your provided code
snippet in a Asp.net1.1 project Page_Load event(my test machine is Win2003
SP1 with VS.net2003 and VS2005 installed). The project's directory is using
Asp.net1.1 and running under default application pool with identity
NetworkService acount. However, the code runs well in the project both
under debugger and without debugger.

Can you provide the detailed information regarding this error? What is the
exception type of this error? You'd better provide the complete call stack
of this error. This will help us to identify if this error is a .Net code
access security exception or native Win32 eventlog access control
exception.

I will wait for your further information, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

Aug 14 '06 #7
Hi Jerry,

Can you first confirm if you are using VS2005 or VS.net2003 in the project?

Below is the source code of System.Diagnost ics.EventLog.Op enForWrite()
method:

private void OpenForWrite()
{
if (this.disposed)
{
throw new ObjectDisposedE xception(base.G etType().Name);
}
if ((this.sourceNa me == null) || this.sourceName .Equals(string. Empty))
{
throw new ArgumentExcepti on(SR.GetString ("NeedSourceToO pen"));
}
SharedUtils.Che ckEnvironment() ;
this.writeHandl e =
UnsafeNativeMet hods.RegisterEv entSource(this. machineName, this.sourceName );
if (this.writeHand le == IntPtr.Zero)
{
Win32Exception exception1 = null;
if (Marshal.GetLas tWin32Error() != 0)
{
exception1 = EventLog.Create SafeWin32Except ion();
}
throw new
InvalidOperatio nException(SR.G etString("CantO penLogAccess"), exception1);
}
}

With the code, we can determine that your code fails in RegisterEventSo urce
win32 API calling.

In the document below, you will see that the RegisterEventSo urce needs
ELF_LOGFILE_WRI TE permission:
"Event Logging Security"
http://windowssdk.msdn.microsoft.com.../ms684080.aspx

Since your code runs well on my test environment, I suspect if the account
your exeuction thread runs under has some different feature. Can you tell
me what authentication mode you are using in you Asp.net project? Basic
authentication or Windows authentication? Do you use any impersonation in
your project?

In your LoginV6.Page_Lo ad method, I recommend you print out the following
information on the page for troubleshooting purpose:

Imports System.Diagnost ics
Imports System.Security .Principal
Public Class WebForm1
Inherits System.Web.UI.P age

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim id As IIdentity = WindowsIdentity .GetCurrent()
Me.Response.Wri te(id.Name + "<br>")
Me.Response.Wri te(id.IsAuthent icated.ToString () + "<br>")
Me.Response.Wri te(id.Authentic ationType + "<br>")
.....
End Sub
End Class

Please provide the output information to me. Thanks.

Once you determined the running account of the current thread, you may
modify the DACL setting of eventlog in registry with SDDL format.

On W2K3, the security of Application Event Log is controlled by CustomSD
registry value in key below:
HKEY_LOCAL_MACH INE\SYSTEM\Curr entControlSet\S ervices\Eventlo g\Application

CustomSD REG_SZ registry value is described by default in SDDL format as
below:
O:BAG:SYD:(D;;0 xf0007;;;AN)(D; ;0xf0007;;;BG)( A;;0xf0007;;;SY )(A;;0x7;;;BA)( A
;;0x7;;;SO)(A;; 0x3;;;IU)(A;;0x 3;;;SU)(A;;0x3; ;;S-1-5-3)

In order for any authenticated user to be able to write to Application
Event Log, you will append:
(A;;0x3;;;AU)

where AU is referring "Authentica ted Users".

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

Aug 15 '06 #8
Additionally, if you are curious, the article below describes the meaning
of the SDDL SID string:
http://windowssdk.msdn.microsoft.com.../ms723312.aspx

While the 0x3 means Read|Write, it is documented in the "CustomSD" section
of the link below:
http://windowssdk.msdn.microsoft.com.../ms684058.aspx

Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

Aug 15 '06 #9
Hi Jerry,

Have you reviewed my last 2 replies? Does it make sense to you? If you
still have any concern or need any help, please feel free to tell me,
thanks!

Best regards,
Jeffrey Tan
Microsoft Online Community Support
=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

Aug 17 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
19155
by: Yitzhak | last post by:
I am having "Permission denied" error while calling LogEvent method of WScript.Shell component. Basically, ASP page calls Windows Script Host Shell component to log events to the OS Application Event log. My environment: Windows Server 2003, IIS 6, WSH, Classic ASP, Vbscript Below is the code and the error: Code:
8
426
by: matt breedlove | last post by:
(x-posted to microsoft.public.dotnet.general and microsoft.public.dotnet.languages.vb) Hello all. I am currently creating a Windows Service using VB.NET and would like to return an error if something goes wrong during startup, IE: parsing a configuration file. The only way I know of is to throw an exception, and this will prevent the
2
3042
by: Lucas Tam | last post by:
Without writing try/catch statements is there a way to have a global error handler in VB.NET? In ASP.NET there is an application level error handler inside Global.asax, but is there something similar for VB.NET winform programs? Thanks! -- Lucas Tam (REMOVEnntp@rogers.com) Please delete "REMOVE" from the e-mail address when replying.
0
2047
by: Kevin | last post by:
I'm writing a service in VB.NET. Reference the following code: Dim oStreamWriter As StreamWriter .... .... .... oStreamWriter = File.CreateText(TempLogFile) If Err.Number <> 0 Then EventLog.WriteEntry("LogService", "Error Creating Log File: " & _ TempLogFile & vbCrLf & _
0
1306
by: John | last post by:
I am writing a custom httpmodule, I can catch BeginRequest, EndRequest event, But I can not catch Error event, I tried throwing an error from my Web Service, creating a security exception (by login the web service with invalid user name 3 times) Did I do any thing wrong here? (VS2005) Please advice. Thanks in advance. John
0
3598
by: David Lozzi | last post by:
Howdy, I'm working on some error handling for my application. Currently on WinXP Pro SP2. Basically this is what I'm doing: Try...Catch at the method level, Catch sends email with error Page_error has code: Throw Server.GetLastError
7
4835
by: EManning | last post by:
Using A2003. I'm receiving this error when returning from a "DoCmd.OpenReport..." statement. I have a tab control with a subform on every tab. The user selects an item from a combobox at the top of the main form which refreshes all the subforms. If this DoCmd statement is not executed, then I don't receive the error. I tried a "DoCmd.OpenQuery..." instead of a report but get the same error. I want the user to be able to...
2
19459
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I will be writing this article intended for those who are in the same level, or maybe lower, of my technical knowledge. I would be using layman's words, or maybe, my own words as how I understand them, hoping, you will understand it the same way that...
11
5579
by: xenoix | last post by:
hey there, im reasonably new to C# and im currently writing a backup application which im using as a learning resource. My PC :- Visual Studio 2005 .NET Framework 2 Component Factory Krypton Tools Test PC :- .Net Framework 2
0
2897
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I will be writing this article intended for those who are in the same level, or maybe lower, of my technical knowledge. I would be using layman's words, or maybe, my own words as how I understand them, hoping, you will understand it the same way that...
0
8445
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8871
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8781
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8551
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8640
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6198
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5664
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4369
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.