Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enterprise Library exception handling and event log issue

Status
Not open for further replies.

justTryingToCode

Programmer
Nov 14, 2006
13
0
0
US
Hi all experts,

I am currently using the Microsoft.Practices.EnterpriseLibrary.ExceptionHandling along with the logging component within a web application.

All was working great, catastrophic errors were logging to the Application event log using the web.config listeners. I decided that I wanted to try giving each new app its own event log. While building a template web.config file I reference Log="Custom Application". Now when I try and change my original applications event log destination it will not write to this event log.I switch it back to "Application" it logs again. here is the web.config entry:

<add source="Gateway Error Logging" formatter="Text Formatter"
log="Application" machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
name="EventLog_Errors" />

I used this same code for another web app which does log to "Custom Application" using the same code, but if I change it to try and log to "Application" it does not. I have reset IIS, restarted my server and made sure ASP.NET permissions exist

Has anyone else had this issue, I have been pulling my hair out trying to figure this out.

Thanks in advance...



 
I finally figured it out:

<EventLogFile> name and Source need to be unique.

And if you are going to create a new log file make sure your name is not a reserve word.. I found out that Gateway was a reserved word.



 
You might try and make a test page that just does the log, so you can see the error message. How did you set up the log. Typically I'd create a simple console installation program as the rights of a running asp.net process never seem enough to create initiate the error log.


private const string _logName = "logname";
private const string _logSource = "sourcename";
internal const string regKey = @"SYSTEM\CurrentControlSet\Services\Eventlog\logname";

public static bool InitializeLog()
{
bool status=false;

if (!EventLog.SourceExists(_logSource))
{
EventLog.CreateEventSource(_logSource, _logName);

status = true;
}
else
{

status = false;
}

// HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\logname
// "(A;;0x0002;;;DU)"
RegistryKey regkey = Registry.LocalMachine.OpenSubKey(regKey, true);
string customSd = (string)regkey.GetValue("CustomSD");
if (!customSd.Contains("(A;;0x0002;;;DU)"))
{
customSd += "(A;;0x0002;;;DU)";
regkey.SetValue("CustomSD", customSd);
Registry.LocalMachine.Flush();
}

return status;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top