Downlaod EventViewer Log and Save in Database

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”&gt;
<html xmlns=”http://www.w3.org/1999/xhtml”&gt;
<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

Advertisements

11 thoughts on “Downlaod EventViewer Log and Save in Database

  1. Pingback: stud poker
  2. 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 .

  3. In truth, electronic bingo can be found enjoyment through a lot of
    people as it is quite fascinating when you work through this stigma of
    the Weekend Sociable varieties of online games commonly viewed as set-aside regarding old-age homes or even cathedral fundraisers.
    Think about the multi-billion buck resorts throughout Las
    vegas (yes, that’s

  4. Today, while I was at work, my cousin stole my iphone and tested
    to see if it can survive a 25 foot drop, just so she can be a youtube
    sensation. My apple ipad is now broken and
    she has 83 views. I know this is completely off topic but I had to share it with someone!

  5. Obtaining wasted appears to be this concept in this article, although My spouse and i meant to select exactly how to address your buddies although gambling it would appear
    that gambling and drinking in this posting are classified as the very same.
    As we go more and additional directly into age technologies,
    the internet is constantly on the advance in addition to generate more entertainment possibilities practically each and every day.

  6. Higher rollers are also conscious of which they are
    going to drop in the long-term, however if they may
    lose at any rate, you could start to lose the particular bare minimum income?
    You know exactly how this account finishes.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s