<body><script type="text/javascript"> function setAttributeOnload(object, attribute, val) { if(window.addEventListener) { window.addEventListener('load', function(){ object[attribute] = val; }, false); } else { window.attachEvent('onload', function(){ object[attribute] = val; }); } } </script> <div id="navbar-iframe-container"></div> <script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script> <script type="text/javascript"> gapi.load("gapi.iframes:gapi.iframes.style.bubble", function() { if (gapi.iframes && gapi.iframes.getContext) { gapi.iframes.getContext().openChild({ url: 'https://www.blogger.com/navbar.g?targetBlogID\x3d8211560\x26blogName\x3dTech+Tips,+Tricks+%26+Trivia\x26publishMode\x3dPUBLISH_MODE_BLOGSPOT\x26navbarType\x3dBLUE\x26layoutType\x3dCLASSIC\x26searchRoot\x3dhttp://mvark.blogspot.com/search\x26blogLocale\x3den\x26v\x3d2\x26homepageUrl\x3dhttp://mvark.blogspot.com/\x26vt\x3d-5147029996388199615', where: document.getElementById("navbar-iframe-container"), id: "navbar-iframe" }); } }); </script>

Tech Tips, Tricks & Trivia

by 'Anil' Radhakrishna
An architect's notes, experiments, discoveries and annotated bookmarks.

Search from over a hundred HOW TO articles, Tips and Tricks


Clocking hours worked using the Event log

If you are a geek you probably don't keep count of the countless hours you spend before your comp. Assuming you use a Windows 2000 (or a newer) OS, you can find the time you logged in & logged out each day (and the time spent in a day) programmatically from the Event log.

Place the code below in the Page_load event of a C# webform after adding the namespace ... using System.Diagnostics;



string log="System";
string machine="type-your-machine-name-here";

if(!EventLog.Exists(log,machine))
{
Response.Write("The log does not exist!");
return;
}

EventLog aLog = new EventLog();
aLog.Log = log;
aLog.MachineName = machine;

Response.Write("There are {0} entr[yies] in the log:" + aLog.Entries.Count);

foreach (EventLogEntry entry in aLog.Entries)
{
//the event code for Login event is 6005
if (entry.EventID == 6005)
{
Response.Write("Login:" + entry.TimeGenerated+ "");
}
if (entry.EventID == 6006)
{
Response.Write("======Logout:" + entry.TimeGenerated + "" );
}
}


The event log can be both a source and a destination for diagnostic information.. All the classes required for logging events to the windows event log are in the System.Diagnostics package. The most important class is the EventLog class

Labels:

Tweet this | Google+ it | Share on FB

« Home | Next »
| Next »
| Next »
| Next »
| Next »
| Next »
| Next »
| Next »
| Next »
| Next »

»

Post a Comment