Well, I'm about to start developing an admin section to an internal-web-app we use in our office and I want to add a logging class to it to track wo does what, when, and what the result was...etc.
user Michael Smith attempted to access Customer Records for Smith, John at 12:45pm on Wednesday, November 28, 2007. Failed.
user Jonathan Sampson accessed Customer Records for Smith, John at 12:53pm on Wednesday, November 28, 2007. Success.
user Jonathan Sampson deactivated Customer Account for Smith, John at 1:28pm on Wednesday, November 28, 2007. Success.
That sort of thing, of course the values would be pulled from the database.
So I'm curious to hear how you guys have designed your classes in the past. Do you have enumerated lists within your class to manage your event-types ("Accessed an account", "Removed an account", "Created an account")
I've never really designed a class like this before, so I'm coming from a completely blank-slate...which I guess is cool ![]()
Jonathan
-
-
That's exactly when aspect-oriented programming would come in handy.
I did such a logger once upon a time. I was lucky since I had one single method that I passed in the stuff that had to be saved and another method that I passed in the stuff that had to be loaded.
What I did was outputting something like:
User INSERT <TABLE> <paramslist> SUCCESS
where I used to parse the SQL statement and success of that method to return me that string.
You could probably go with an enum that is converted to a string (by a method that perhaps does a lookup in a resources file) to determine your action...
You could perhaps even go further and store the data that you require for your logging in a database and define some rules (dunno if you could do that directly in the database - depents on your scenario) that are then looked up in the database and applied... -
you have to provide more information about how you implemented the business logics of your web-application.
You can create a user class, and in that user class, define options in the form of a switch statement.
switch (UserRequest)
{
case "A":
Console.WriteLine ("user {0} has done {1} at {2}", userClass.UserName, userClass.Accessed, DateTime.Now.ToString());
//etc...
default:
break;
}
it depends on your implementation. -
jsampsonPC wrote:Well, I'm about to start developing an admin section to an internal-web-app we use in our office and I want to add a logging class to it to track wo does what, when, and what the result was...etc.
user Michael Smith attempted to access Customer Records for Smith, John at 12:45pm on Wednesday, November 28, 2007. Failed.
user Jonathan Sampson accessed Customer Records for Smith, John at 12:53pm on Wednesday, November 28, 2007. Success.
user Jonathan Sampson deactivated Customer Account for Smith, John at 1:28pm on Wednesday, November 28, 2007. Success.
That sort of thing, of course the values would be pulled from the database.
So I'm curious to hear how you guys have designed your classes in the past. Do you have enumerated lists within your class to manage your event-types ("Accessed an account", "Removed an account", "Created an account")
I've never really designed a class like this before, so I'm coming from a completely blank-slate...which I guess is cool
Jonathan
well you can do several kinds of logging and if you need a really good traking then IMHO you should impliment multiple logs.
for example if you use the asp.net membership system you can log asp.net events to the event log and to a database table.
this can for example log login errors and application exceptions...
more later on sql logging. -
Ok back from Lunch

SQL and data; depending on what you need for the system sql triggers that log updates and deletes may be a good thing.
there are several ways to do this but they all center around the idea that a trigger will fire inthe sql server when the table is updated.
even if for example the user gets a sql connection via some other app that does not use your business logic, say they use MS access and mess with the data....
they will not know that the triggers will store the edits....
you can log the date and time of the edits and "undo" the chnages and possibly also log what sql user login was used to find the guilty parties.
by hand this audit trail can be a bee to create, google around and you will find many ways folks have done them.
one I read of but have not yet used is a SQL CLR based package.
with SQL CLR you could create one set of C# routines to do the work and one table to hold the log.
then you could add and remove logging on any table with minimal work.
example of log table:
ID
DateTime
TableRowID
TableName
ColumnName
OldValue
LoginUserID
so you take a table and select all the rows with that table name ordered by datetime desc and you can re-create any edits. or prior version of the data.
trade offs.. ok this writes a bunch of rows but only saves the columns you want to track, and works even if you alter the table at some point (well works as good as it can)
some folks create a dupe table and just dunmp the whole row....
but then you have 2 x the tables as your database and a different trigger for every table. -
about asp.net logging, look at this snipet:
<healthMonitoring>
<!-- Event Log Provider being added. -->
<providers>
<add name="EventLogProvider" type="System.Web.Management.EventLogWebEventProvider,System.Web,..." />
</providers>
<!-- Event mapping provides a friendly name to the events based on the WebBaseErrorEvent class. -->
<eventMappings>
<add name="All Errors" type="System.Web.Management.WebBaseErrorEvent,System.Web,.." startEventCode="0" endEventCode="2147483647" />
</eventMappings>
<!-- Rule tying the "All Errors" event mapping to the EventLog Provider. -->
<rules>
<add name="All Errors Default" eventName="All Errors" provider="EventLogProvider" profile="Default" minInstances="1" maxLimit="Infinite" minInterval="00:01:00" custom="" />
</rules>
</healthMonitoring>
this goes in the web.config
it will log asp.net events to the event log, you can also use the same setup to send data to sql server or other targets.
and I think you can raise custom events in your web code that get logged the same way.
so you could raise a "user opened form" event and a "user added foo" event and so forth... -
Yea use something out of a package as your base
OR:
Make a lookup table for error codes in standard form like:
Event[0001]: <bLandon> Loggged in.
Then have a lookup table:
Code Desc Type
0001 - Log in - N
Then a Action Table:
ID Desc Command
N No Action NULL
Then you can have a command interpreter that does nothing on NULL and does other things when something else is passed in Like:
EMAIL <admin@mysite.com> ALL CONTENTS
You could even get as fancy as making powershell commandlets and make the command field contain power shell code. See last months MSDN magazine for more on building custom comandlets.
You could then have shell session going that has as limited a command set as you want.
That way its a database change to change actionable items to other actions or do nothing events or errors.
Hope this gives you some ideas.
Thread Closed
This thread is kinda stale and has been closed but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.