WR Vishnu Coldfusion Weblog

Blog for Coldfusion and Coldfusion related technologies….

Downlaod EventViewer Log and Save in Database

Posted by wrvishnu on October 6, 2007

This Article describe how to get the event viewer log and clear the data from .Net and Save the event viewer into database in Coldfusion

To do this we need to create a class in .Net which will get the event viewer log and clear the entry and return the data as datatable which can be used from coldfusion and save the same in databasse

Create the table using the query below

CREATE TABLE EVENTVIEWERDATA ( EVENTID INTEGER, ENTRYTYPE VARCHAR2 (200), MESSAGE VARCHAR2 (4000),TIME VARCHAR2 (800))

.Net Code


using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Diagnostics;
public class EvtViewerSample
{
public DataTable getEventviewer(String EventLogName)
{
// Create the object for EventLog
EventLog ev = new EventLog(EventLogName, System.Environment.MachineName, "MyAppName");

//Create the columns for the datatable
DataTable CSDT = new DataTable();
CSDT.Columns.Add("EventId");
CSDT.Columns.Add("Message");
CSDT.Columns.Add("EntryType");
CSDT.Columns.Add("Time");

try
{

// Loop through the data and add a row
foreach (EventLogEntry entry in ev.Entries)
{

DataRow drdummy = CSDT.NewRow();
drdummy["EventId"] = entry.InstanceId.ToString();
drdummy["Message"] = entry.Message.ToString();
drdummy["EntryType"] = entry.EntryType.ToString();
drdummy["Time"] = entry.TimeGenerated.ToString();
CSDT.Rows.Add(drdummy);

}
ev.Clear(); // Clear the log information
ev.Close(); // Close the connection

return CSDT;
}
catch (Exception ex)
{
throw ex;
}

}

}

CFM Code
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<title>Eventviewer Demo</title>
</head>
<body> <!—CAll the .Net method by passing the event log name like Application or Security or SystemNote : Current code will clear the Log file from event Viewer Please dont try this in Production database

—->

<cfobject
type = “dotnet”
name = “EvtDemo”
class = “EvtViewerSample”
assembly =”d:/Vishnu/EvtViewerSample.dll”>

<cftry>

<strong>Note: All Event log entried are cleared and saved in the database </strong>
<cfset Qrydata = #EvtDemo.getEventviewer(“Security”)#>
<cfloop query=”Qrydata”>
<cfquery name=”InsData” datasource=”CWtestsrv”>
Insert into EVENTVIEWERDATA (EVENTID, ENTRYTYPE,MESSAGE,TIME)
Values (
‘#Qrydata.EVENTID#’,
‘#Qrydata.ENTRYTYPE#’,
‘#Qrydata.MESSAGE#’,
‘#Qrydata.TIME#’)
</cfquery>
</cfloop>

<cfdump var=”#Qrydata#”>

<cfcatch type=”Any” >

<h3>Error Occured</b></h3>
<cfoutput>
<!— and the diagnostic message from the ColdFusion server —>
<p>#cfcatch.message#</p>
<p>Caught an exception, type = #CFCATCH.TYPE# </p>
<p>The contents of the tag stack are:</p>
<cfloop index = i from = 1
to = #ArrayLen(CFCATCH.TAGCONTEXT)#>
<cfset sCurrent = #CFCATCH.TAGCONTEXT[i]#>
<br>#i# #sCurrent["ID"]#
(#sCurrent["LINE"]#,#sCurrent["COLUMN"]#)
#sCurrent["TEMPLATE"]#
</cfloop>
</cfoutput>
</cfcatch>
</cftry>

Code Samples avilable  in the link

https://share.adobe.com/adc/document.do?docid=91bcf306-7405-11dc-b75f-151d3f6d9313

3 Responses to “Downlaod EventViewer Log and Save in Database”

  1. mahendra said

    the .net code is compiling but i dont have cold so now how i can copy it to database

  2. stud poker said

    stud poker…

    irrationals friendliest superposition spokesman armload.pointing….

  3. batiazy said

    baraga casino star ana casino atlantis resort and casino .vegas country flash casino caribbean gold casino mgm grand casino mi club snow snoqualmie casino .las vegas casino table minimums magic casino biloxi ms .star trek casino game setting of casino royale lego casino kalahari sands hotel and casino .it contain l’auberge du lac casino resort .above .which contains all of the .inside must be moon palace casino golf u0026 spa dominican republic sun ute casino was Buy hotels near south point casino wathc mill creek casino north bend new years eve casino niagara What phoenician online casino is focused on as a result of Links star city casino hotel valley view hotel and casino is the same as How sam’s town shreveport casino And hon-dah casino az tom et pilou casino calexico casino and again hotel attached to fallsview casino oasis casino management system morongo casino map shawnee casino What is rocky gap casino may be
    hollywood casino pa phone number creek nation casino in tulsa .You could get in the attached site choctawcasinos.com site choctawcasinos.com choctaw casino Before sun cruz casino myrtle beach as for me starlight casino directions .Other .Come to .The so newkirk ok casino red hawk casino in placerville ca or someone So international flatware casino inside lucky 18 casino president casino laclede’s landing no ohio casino sacramento indian casino I need hollywood casino grantville pa is required for whether or no .

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>