Hi all...
Once again... In trouble....
Please guide me... How to build event logs in any asp.net c# website ??
Requirement -
1. If a user opens a portal, then the system must capture the page name (index.aspx), the user name, and current time. - Done.
2. If user clicks on any button (say btn_Save, btn_Search), then system much capture the pagename, username, button-id, button-text that was clicked, and time.
In short... How to create such event logs for asp.net website / portals ?
Currently there are 20 web pages in the portal.
Do I need to use System.Diagnostics namespace??
--------------------------------------
Other Point -
I have recently faced an incident.
I had uploaded my published files on the iis server.(Remote Desktop Connection)
The system was running smoothly.
But... One other person from other team entered the server and changed the physical path of my portal.
By this, I got many complaints from the users that the site is not working.
-------
Is there any way in which we can find out who enters the server and make such changes ??
-----
Is there any way in which we can capture the username/windows name and find the activities done on server ??
--
Please guide.
Thank you all in advance...
Loading

Jitendra KumarRank #760 · 3K reputationPosted Mar 21, 2015, 5:57 AM EDT
Create log file using Function like this :-
public static void CreatErrorLog(string strMsg)
{
string strLogFilePath = null;
if (System.IO.Directory.Exists("d:\\ErrorLog") == false)
{
System.IO.DirectoryInfo dirELogs = default(System.IO.DirectoryInfo);
dirELogs = System.IO.Directory.CreateDirectory("d:\\ErrorLog");
}
strLogFilePath = "d:\\ErrorLog\\ErrorLog_";
FileStream fs1 = default(FileStream);
StreamWriter sw = default(StreamWriter);
DataSet dsFile = new DataSet();
try
{
if (System.IO.File.Exists(strLogFilePath) == false)
{
fs1 = new FileStream(strLogFilePath, FileMode.Create);
sw = new StreamWriter(fs1);
sw.WriteLine(msg.Trim());
sw.WriteLine("-----------------------");
sw.Close();
fs1.Close();
}
else
{
fs1 = new FileStream(strLogFilePath, FileMode.Append, FileAccess.Write);
sw = new StreamWriter(fs1);
sw.WriteLine(msg.Trim());
sw.WriteLine("-----------------------");
sw.Close();
fs1.Close();
}
}
}
And Now call this function with value whatever you want to show in log.
Like CreatErrorLog("hello")
CreatErrorLog(Page.Name + btn.Name)
If any problem or query plz revert me.
Riddhi ValechaRank #794 · 2.9K reputationPosted Mar 22, 2015, 3:47 AM EDT
I need all these things in database (sql server).
Example -
-----------
How do I achieve this ??
Jitendra KumarRank #760 · 3K reputationPosted Mar 22, 2015, 4:09 AM EDT
In Function you write code for insert data in database like this :-
public static void CreatErrorLog(string Pagename, string ctrlname, string ctrlid, string ipaddress, string txt)
{
MySqlConnection conn = new
MySqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
conn.Open();
MySqlCommand cmd = new MySqlCommand("Insert into student (pagename,ctrlname,ctrlid,ipaddress, txt)
values (pagename,ctrlname,ctrlid,ipaddress, txt)", conn);
}
And Now call this function with value.
Get Page page Name -- Path.GetFileNameWithoutExtension(Request.Path);
Button Name in get in btnclick event
For IP Address See links :-
http://stackoverflow.com/questions/19285957/how-to-get-public-ip-address-of-a-user-in-c-sharp
http://www.aspsnippets.com/Articles/How-to-get-IP-Address-of-Visitors-Machine-in-ASP.Net.aspx
Like CreatErrorLog(Path.GetFileNameWithoutExtension(Request.Path), buttonname, id, ip, txt);
If any problem or query plz revert me.
Riddhi ValechaRank #794 · 2.9K reputationPosted Mar 24, 2015, 11:24 PM EDT
PLease let me know how to calculate time taken for code in button_click to execute ??
button_click()
{
//10 lines of c# Code
}
--
How many seconds/ milli seconds are required to execute these 10 lines.
----
There are 8 methods in my application, in which there are more parameters(more than 9).
The portal was developed in 2012 (don't know by whom).
I know, that more parameters in a method is not a good programming practice.
I want to know -
1. Time taken to execute a method with 1 parameter.
2. Time taken to execute a method with 9 and more parameters.
---
Difference between less and more number of parameters in a method...
Please Guide... Thanks in advance..
Jitendra KumarRank #760 · 3K reputationPosted Mar 25, 2015, 3:19 AM EDT
Riddhi ValechaRank #794 · 2.9K reputationPosted Mar 26, 2015, 5:24 AM EDT
System.DIagonstics namespace has Stopwatch...
This calculates time in milliseconds.
But, What to do if I want to calculate machine time, CPU Time, get resources used by CPU, time taken by each resource, etc.
In Short, How to calculate CPU Time ???
Jitendra KumarRank #760 · 3K reputationPosted Mar 26, 2015, 9:35 PM EDT
For CPU Performance you use
PerformanceCounter Class
See Links :-
https://msdn.microsoft.com/en-us/library/system.diagnostics.performancecounter.aspx
http://stackoverflow.com/questions/4679962/what-is-the-correct-performance-counter-to-get-cpu-and-memory-usage-of-a-process
Riddhi ValechaRank #794 · 2.9K reputationPosted Mar 28, 2015, 3:43 AM EDT
System.Diagnostic namespace will not give CPU usage.....
I need CPU time, CPU Resources, etc that are used when running a website...
Jitendra KumarRank #760 · 3K reputationPosted Mar 28, 2015, 5:04 AM EDT
Kindly share your code for more understanding.
Riddhi ValechaRank #794 · 2.9K reputationPosted Mar 29, 2015, 1:23 AM EDT
I cannot share the code.
Can you post code-lines here ??
1 more thing... I am working on Visual Studio 2012 and SQL Server 2008.
Riddhi ValechaRank #794 · 2.9K reputationPosted Apr 5, 2015, 1:11 AM EDT
Also..let me know how to get the memory usage ??
Gowtham RajamanickamRank #57 · 29K reputationPosted Apr 6, 2015, 12:31 AM EDT
Riddhi ValechaRank #794 · 2.9K reputationPosted Apr 6, 2015, 4:01 AM EDT
I need CPU time..