Activity and Exception Logging

Znode Logging

Znode Storefront provides the ability to log events programmatically. This facility can be used for debugging and also for monitoring important events on your web site.

 

There are two basic types of logging provided, file and database. File logging is intended to be used for debugging purposes and should not be used in a production environment. Database logging is used to record things such as user login events or payment failures. Database logging is required for PCI compliance.

 

Each of these logging types can be used in your code for whatever purpose you need.  By default basic logging is already be defined in Znode Storefront.

File Logging

The log file for Znode Storefront is located at Web/Data/Default/Logs/ZnodLog.txt. For file logging to work you must ensure that this file is writable by the  Network Service user.  File logging can be turned on or off by setting the following in the web.config:

 

<add key="EnableLogging" value="1"/>

 

There are two basic methods that are available.

 

public static void LogObject(Type objectType, Object objectInstance)

 

This method will dump the contents of an object out to the log file.

 

ObjectType – The type of object that you want to log. This function will use this information to determine the structure of the object passed in.

ObjectInstance – An instance of the object that you would like to log.

 

public static void LogMessage(string Message)

 

This method writes a message to the log file.

 

Message – A message that you would like to write out the ZnodeLog.txt file.

Database Logging

Database logs are written to the ZNodeActivityLog in the database. There is a related table, ZNodeActivityLogType that defines names for each of the logging event types. When customizing your own logging you will want to define your events in the ZNodeActivityLogType table. Events that can’t be logged into the database because they have not been defined will be written out to the file log instead.

 

Several error numbers are pre-defined for you in the Znode.Libraries.Framework.Business DLL. These error numbers are used internally to this DLL and must be defined in your database in the ZNodeActivityLogType table in the ActivityTypeId. Znode Storefront ships with these entries defined. Feel free to use these error numbers for your own use.

 

        public enum ErrorNum

        {

            GeneralError = 1,

            GeneralWarning = 2,

            GeneralMessage = 3,

            LoginSuccess = 1000,

            LoginFailed = 1001,

            LoginCreateSuccess = 1002,

            LoginCreateFailed = 1003,

        }

 

The following are the basic methods for logging to the database. There are several overloaded functions to make writing your code easier but they each function in much the same way.

Record an Activity

This function records an event to the ZNodeActivityLog table

 

public static void LogActivity(int ActivityTypeId, string Data1, string Data2, 

                       string Data3, string Status, string LongData)

 

ActivityTypeId – This is your error number and must be defined in the ZNodeActivityLogType table.

Data1 – This is a place for you to store any custom data that you would like to log. You can save up to 255 characters and this field is indexed in the database.

Data2 – This is a place for you to store any custom data that you would like to log. You can save up to 255 characters and this field is indexed in the database.

Data3 – This is a place for you to store any custom data that you would like to log. You can save up to 255 characters and this field is indexed in the database.

Status – A placeholder for writing any status information that you would like to save. Typically in Znode Storefront this field is used to provide further detail about the event that has been logged.

LongData – This filed is provided to allow storage for up to 4000 characters of your information.

Start Transaction Monitoring

This function will make an entry into the ZNodeActivityLog table marking the start time of your event by setting the CreateDte entry for this log entry.

 

public void LogActivityTimerStart ()

End Transaction Monitoring

This function will log the end time of your logging activity as well as other data that you would like to collect. With this function and the LogActivityTimeStart function you will be able to keep metrics on how long events take. The begin and end time will be recorded in the CreateDte and EndDte columns of the ZNodeActivityLog table.

 

public void LogActivityTimerEnd(int ActivityTypeId, string Data1, string Data2, 

                       string Data3, string Status, string LongData)

 

ActivityTypeId – This is your error number and must be defined in the ZNodeActivityLogType table.

Data1 – This is a place for you to store any custom data that you would like to log. You can save up to 255 characters and this field is indexed in the database.

Data2 – This is a place for you to store any custom data that you would like to log. You can save up to 255 characters and this field is indexed in the database.

Data3 – This is a place for you to store any custom data that you would like to log. You can save up to 255 characters and this field is indexed in the database.

Status – A placeholder for writing any status information that you would like to save. Typically in Znode Storefront this field is used to provide further detail about the event that has been logged.

LongData – This filed is provided to provide storage for up to 4000 characters of information.

 

 


See Also:

Application Monitoring

Diagnostics