IIS Development

IisDev

>  Home
>  News
>  Notification Service

 

Articles

>  Code Samples
>  ASP.NET
>  Security

 

Components & Tools

>  Free Components
>  SharpDevelop
>  ComponentCenter
>  CodeLook Program

 

Service

>  Links
>  Advertising
>  Contact us

Search IISDEV:

AspEventlog 2.0 Component - free

Last updated: 06/21/99, v2.0 (01/20/99 Initial Release)
New Features: remote logging, custom event sources, easier logging support.


You can log additional information to the site logs using Response.AppendToLog, however, sometimes it is important to see events reported to a more central log of Windows NT itself - the Application eventlog (like the Application_OnStart event in global.asa). You can use Event Viewer immediately to filter for events, without having to go to the log files and processing them.

The AspEventlog component can be used from any OLE Automation enviroment, including but not limited to ASP (though the name would imply that). It registers itself with the eventlog during the standard OLE registration process.

The component's interface is intended to be simple, but powerful if you want to have events reported to the Application eventlog of the local server (works with a standard installation, aka server runs under IUSR_machinename account). All four different event types (success, error, warning and information) can be logged, together with a single string of information (you are free to include anything in this string, like IP, user agent, etc). See the sample for how to do that.

Methods

Open()
Opens the Application event log on the local computer. The event source is "AspEventLog".
OpenEx(ComputerName,SourceName)
Opens the Application event log on the computer you specify, and registers the event source you specify. If you want to open the local computer's event log, supply vbNullChar as the ComputerName. If you supply a SourceName different from "AspEventLog", you first need to create the event source.
Close()
Closes the currently open event log.
ReportSuccess(EventDescr)
Reports a success event to the opened event log.
ReportError(EventDescr)
Reports an error event to the opened event log.
ReportInformation(EventDescr)
Reports an informational event to the opened event log.
ReportWarning(EventDescr)
Reports a warning event to the opened event log.
ReportEvent(wEventType,EventDescr)
Generic reporting function (introduced in 1.0), which takes the event type as first parameter. See the samples for the 4 valid event types or use the preceding four new methods to report events of the corresponding event type.
CreateEventSource(EventSource)
Creates a new event source. Use it when you want to report events under a special event source (eg "My Source" instead of "AspEventLog"). Due to the nature of event logging, event sources must be registered in the registry before the reported events can be displayed. This method can register event sources only on the local machine.
DeleteEventSource(EventSource)
Deletes the registry entries of a previously created event source.

Samples

The component ships with an Excel workbook that demonstrates many of the useful usage scenarios of the component (including remote logging and the creation of custom event sources). The reason why it is implemented as Excel example is that you can interactively test the code (much easier than in ASP). However, you can take the code and port it to ASP (ok, you can use it in any Automation environment).

Below is an example of such a port to ASP.

<% Option Explicit %>
<!-- Christoph Wille, 20.1.99 -->


<%
Const EVENTLOG_SUCCESS = 0
Const EVENTLOG_ERROR_TYPE = 1
Const EVENTLOG_WARNING_TYPE = 2
Const EVENTLOG_INFORMATION_TYPE = 4
%>

<%
' Create the AspEventlog object
Dim xObj, bResult
Set xObj = Server.CreateObject("SOFTWING.ASPEventlog")

' open the log and report the status
bResult = xObj.Open()
Response.Write "Open called with return value of: " &  bResult _
	& "<BR>" & vbCRLF

' write a information type event and give feedback
bResult = xObj.ReportEvent(EVENTLOG_INFORMATION_TYPE, _
	"This is a demo event from SOFTWING")
Response.Write "Event was reported successfully: " & bResult _
	& "<BR>" & vbCRLF

' close the log (would be done automatically on object destruction)
bResult = xObj.Close()
Response.Write "Log closed successfully: " & bResult & _
	"<BR>" & vbCRLF

' delete the object and free up memory
Set xObj = Nothing
%>

Installation and Download

Before using the component you have to register it using the regsvr32 utility: regsvr32 AspEventlog.dll.

Download (size is approx. 77KB)
The most current version number of the component is 2.0. It is compiled with Visual C++ 6.0 SP3 using MFC statically linked.

If you do have any questions, please feel free to send mail to Christoph Wille.

 

©1998-2004 Christoph Wille. All rights reserved.
All content and images on this site are copyright. Reuse (even parts) needs our written consent.