473,386 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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("Application")
Logevent.Source = "Application"

Logevent.WriteEntry("Log In Error ", EventLogEntryType.Error)

The error is in the WriteEntry .

Thank you
--
Jerry
Aug 11 '06 #1
9 10968
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("Application")
Logevent.Source = "Application"

Logevent.WriteEntry("Log In Error ", EventLogEntryType.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("Application")
JCLogevent.Source = "Application"
JCLogevent.WriteEntry("Log In Error ", EventLogEntryType.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("Application")
JCLogevent.Source = "Application"
JCLogevent.WriteEntry("Log In Error ", EventLogEntryType.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("Application")
JCLogevent.Source = "Application"
JCLogevent.WriteEntry("Log In Error ", EventLogEntryType.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
"Application" and this soruce "Application" 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]

[InvalidOperationException: Cannot open log for source 'Application'. You
may not have write access.]
System.Diagnostics.EventLog.OpenForWrite(String currentMachineName) +719543
System.Diagnostics.EventLog.InternalWriteEvent(UIn t32 eventID, UInt16
category, EventLogEntryType type, String[] strings, Byte[] rawData, String
currentMachineName) +206
System.Diagnostics.EventLog.WriteEntry(String message, EventLogEntryType
type, Int32 eventID, Int16 category, Byte[] rawData) +269
System.Diagnostics.EventLog.WriteEntry(String message, EventLogEntryType
type) +14
LoginV6.Page_Load(Object sender, EventArgs e) in
c:\inetpub\wwwroot\ContentDepot\LoginV6.aspx.vb:21 8
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +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.Diagnostics.EventLog.OpenForWrite()
method:

private void OpenForWrite()
{
if (this.disposed)
{
throw new ObjectDisposedException(base.GetType().Name);
}
if ((this.sourceName == null) || this.sourceName.Equals(string.Empty))
{
throw new ArgumentException(SR.GetString("NeedSourceToOpen") );
}
SharedUtils.CheckEnvironment();
this.writeHandle =
UnsafeNativeMethods.RegisterEventSource(this.machi neName, this.sourceName);
if (this.writeHandle == IntPtr.Zero)
{
Win32Exception exception1 = null;
if (Marshal.GetLastWin32Error() != 0)
{
exception1 = EventLog.CreateSafeWin32Exception();
}
throw new
InvalidOperationException(SR.GetString("CantOpenLo gAccess"), exception1);
}
}

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

In the document below, you will see that the RegisterEventSource needs
ELF_LOGFILE_WRITE 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_Load method, I recommend you print out the following
information on the page for troubleshooting purpose:

Imports System.Diagnostics
Imports System.Security.Principal
Public Class WebForm1
Inherits System.Web.UI.Page

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim id As IIdentity = WindowsIdentity.GetCurrent()
Me.Response.Write(id.Name + "<br>")
Me.Response.Write(id.IsAuthenticated.ToString() + "<br>")
Me.Response.Write(id.AuthenticationType + "<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_MACHINE\SYSTEM\CurrentControlSet\Servic es\Eventlog\Application

CustomSD REG_SZ registry value is described by default in SDDL format as
below:
O:BAG:SYD:(D;;0xf0007;;;AN)(D;;0xf0007;;;BG)(A;;0x f0007;;;SY)(A;;0x7;;;BA)(A
;;0x7;;;SO)(A;;0x3;;;IU)(A;;0x3;;;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 "Authenticated 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
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...
8
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...
2
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...
0
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...
0
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...
0
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 ...
7
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...
2
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...
11
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...
0
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...

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.