Logging / Exceptions

From Znode Knowledge Base
Jump to: navigation, search

Elmah Error Logging

Znode 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. Each of these logging types can be used in your code for whatever purpose you need. By default, basic logging is already defined in Znode.

  • 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.

File Logging

Znode.Engine.Api\Data\default\logs\{yyyy-MM-dd}\Inside Log ->Demo

Logs are stored as .txt files in Folders named for each corresponding day .For File Logging to work, please 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="EnableDebugging" value="1"/>

There are two basic methods:

Method #1 Method #2
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.log 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 logs, you will want to define your events in the "ZNodeActivityLogType" table. Undefined Events that can’t be logged will be written to the File Log instead.

To enable logging in the database make set the following in the web.config

  • Note: Database logging is required for PCI compliance
<add key="EnableLogging" value="1"/>

Several error numbers are pre-defined for you in the "Znode.Libraries.Framework.Business DLL". These error numbers are used internally for the DLL and must be defined in your database in the "ZNodeActivityLogType" table in the ActivityTypeId.

Znode ships with these entries defined. Feel free to use these error numbers for your own use.

GeneralError = 1

GeneralWarning = 2

GeneralMessage = 3

UpgradeSchema = 100

DiagnosticsPage = 101

DiagnosticsSent = 102

ActivationPage = 103

ActivationSuccess = 104

ActivationFailed = 105

LoginSuccess = 1000

LoginFailed = 1001

LoginCreateSuccess = 1002

LoginCreateFailed = 1003

AccountUnLock = 1104

AccountLock = 1105

PasswordChangeSuccess = 1106

PasswordChangeFailed = 1107

PasswordResetSuccess = 1108

PasswordResetFailed = 1109

UserLogout = 1110

ApplicationStart = 2000

ApplicationEnd = 2001

CreateObject = 3001

EditObject = 3002

DeleteObject = 3003

PaymentSettingsChange = 3004

Imported = 3005

Exported = 3006

ViewObject = 3007

ActivityLogReport= 4001

SubmitPaymentSuccess = 5000

SubmitPaymentFailed = 5001

OrderSubmissionSuccess = 5002

OrderSubmissionFailed = 5003

StoreKeyRotated = 9000

StoreSettingsChangeSuccess = 9001

StoreSettingsChangeFailed = 9002

KeywordSearch = 9500

Productsearch = 9501

SKUsearch = 9502

Record an Activity

public static void LogActivity(int ActivityTypeId, string Data1, string Data2, string Data3, string Status, string LongData, string Target)

This function records an event to the "ZNodeActivityLog" table

  • 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 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.
  • Source – Where this activity is occurring.
  • Target – Which resources are effected by this activity.

Start Transaction Monitoring

public void LogActivityTimerStart ()

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.

End Transaction Monitoring

public void LogActivityTimerEnd(int ActivityTypeId, string Data1, string Data2, string Data3, string Status, string LongData)

This function will log the end time of your logging activity as well as other data that you 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.

  • 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 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.
  • Source – Where this activity is occurring.
  • Target – Which resources are effected by this activity.

Related Links