Write in Event Viewer
Most of the time when you developed an application that more than one user login with his user name and password you want to know Each pressed or each events happened in you application
There is a sample way to do that and store each step in log file With your Log Name !!
like Office , System ,Application,Security Log Names
Let’s Begin :
create class Named SavedRecords
then create method Name RecordTextBox with 4 parameters (Listview ,string ,TextBox ,string )
the method is like :
RecordTextBox(Listview Lst , string UserName , TextBox txtbx , string Value)
{}
Hint:
this Method we will Call it in Each TextBox Leave Event and thats better and reduce the number of records with more details
Ex:
in TextChange Event there will be Records for Each character or any value you enterd
like :
Record1: a
Record2: ah
Record3: ahm
Record4: ahme
Record5: ahmed
but leave Event will Record
Record1: ahmed
inside the Methods
RecordTextBox(Listview Lst , string UserName , TextBox txtbx , string Value)
{
ListViewItem item = new ListViewItem(UserName.ToString());
item.SubItems.Add("Change "+txtbx + " To " +Value);
item.SubItems.Add("At : " + DateTime.Now.ToShortTimeString().ToString());
lstRecords.Items.Add(item);
lstRecords.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
}
what happened here is:
create ListViewItem called Item and give the column One the UserName
then create column 2 for the Events on the textBox Change
then create column 3 for the time of the Event Fire
// You Can Add More than one Column to show in the ListView ( in Details Mode)
then you are free where to call this Method in Closing Event Or in Closed Button or any Event You like
the way to save now in Event Log is:
Make For Loop For Items in ListView:
EventLog log = new EventLog("Bogy Test Log");
log.Source = "AHMED";
for (int i = 0; i < listView1.Items.Count - 1; i++)
{
log.WriteEntry(listView1.Items[i].SubItems[0].Text.ToString() + "\n\n" + listView1.Items[i].SubItems[1].Text.ToString() + "\n\n" + listView1.Items[i].SubItems[2].Text.ToString() + "\n\n" + listView1.Items[i].SubItems[3].Text.ToString(),EventLogEntryType.Information,2);
}
MessageBox.Show("Done");
after that go to your Event Viewer and select the Log Name and see the Result
This help you when any user run your application
its bad idea when using it to know Passwords
I had other way to save these Events I’ll discus it later