Avatar of triplex_noc
triplex_noc

asked on 

InvalidOperationException: Cannot open log for source {0}. You may not have write access

I setup a new W2K3 box for classic ASP and ASPX development. Lot of code, called by classic ASP is within a .NET 2.0 assembly registered to the GAC. Calling .NET 2.0 methods from classic ASP works like a charm with the exception that methods in the assembly that try to write to a custom event log abort with the above mentioned error. It is important to mention, when calling the same methods from a GUI applications or a cmd line wrapper everything is fine. On a previous box this worked fine.

What I did so far:
- added the w3wp worker process with fully trusted security to the custom event log file
- checked that the assembly is in fact in the GAC -> o.k.

My configuration:
Server W2K3R2 with IIS 7.0
- .NET 2.0 version 2.0.50727.42
- VBScript for ASP

Sorry to mention but I can not get rid of the 40.000 lines of ASP classic code, even I would love to ;-(
Any suggestions to this security problem
1. Classic ASP:
set oSync = CreateObject("triplex.mdt.sync") ' create the com object, no error works fine
oSync.forceSync = true ' works fine
res = oSync.UpdatePsEmployeeRecord(emplId, candId) ' calls internally a write to the custom event log and fails.
 
2. C# assembly:
using System;
using System.Diagnostics;
 
[assembly : CLSCompliant(true)]
 
namespace Triplex.Mdt
{
	/// <summary>
	/// Summary description for MyElog.
	/// </summary>
	public class Elog : IDisposable
	{
		private readonly EventLog oElog;
		private bool bConsoleLogging;
 
		///<summary>
		/// event logging
		///</summary>
		public Elog() {
			if (!EventLog.Exists("triplex")) {
				EventLog.CreateEventSource("mds", "triplex");
			}
			oElog = new EventLog {Log = "triplex", Source = "mds"};
		}
 
		#region IDisposable Members
 
		public void Dispose() {
			Dispose();
		}
 
		#endregion
 
		/// <summary>
		/// Success a regular message
		/// </summary>
		/// <param name="strMessage"></param>
		public void Success(String strMessage) {
			if (bConsoleLogging) {
				Console.WriteLine(strMessage);
			}
			oElog.WriteEntry(strMessage, EventLogEntryType.SuccessAudit);
		}
 
		/// <summary>
		/// Success an error
		/// </summary>
		/// <param name="strMessage"></param>
		public void Error(String strMessage) {
			if (bConsoleLogging) {
				Console.WriteLine("Error: " + strMessage);
			}
			oElog.WriteEntry(strMessage, EventLogEntryType.Error);
		}
 
		/// <summary>
		/// Add an informational message
		/// </summary>
		/// <param name="strMessage"></param>
		public void Information(String strMessage) {
			if (bConsoleLogging) {
				Console.WriteLine("Info: " + strMessage);
			}
			oElog.WriteEntry(strMessage, EventLogEntryType.Information);
		}
 
		/// <summary>
		/// add a warning message
		/// </summary>
		/// <param name="strMessage"></param>
		public void Warning(String strMessage) {
			if (bConsoleLogging) {
				Console.WriteLine("Warning: " + strMessage);
			}
			oElog.WriteEntry(strMessage, EventLogEntryType.Warning);
		}
 
 
		/// <summary>
		/// Log failure 
		/// </summary>
		/// <param name="strMessage"></param>
		public void Failure(String strMessage) {
			if (bConsoleLogging) {
				Console.WriteLine("Audit failure: " + strMessage);
			}
			oElog.WriteEntry(strMessage, EventLogEntryType.FailureAudit);
		}
 
		/// <summary>
		/// toogle console logging on/off
		/// </summary>
		/// <param name="bFlag"></param>
		public void setConsoleLogging(bool bFlag) {
			bConsoleLogging = bFlag;
		}
	}
}

Open in new window

SoftwareMicrosoft IIS Web ServerWindows Server 2003

Avatar of undefined
Last Comment
Timetrips

8/22/2022 - Mon