Logging... You can never have too much of it, but you only realize that you don't have enough, when you need it.
There are different ways that you can log information in Dynamicweb:
- You can add information to the Execution Table, i.e., the table shown, when you enter ?Debug=True. This is great for debugging, but the information is only available at runtime.
- Dynamicweb Ecommerce logs information to the EcomOrderDebuggingInfo, and the API offers a static method to populate this table with log entries (see also https://doc.dynamicweb.com/community/devblog/blog/order-log-investigation?PID=8967).
- You can also add information to the Monitoring system in Dynamicweb to have all log information in one place. This approach allows you distinguish between information and errors along with some other levels (see the intellisense suggestions after the GetLogger).
- You can add log entries to log files in the /Files/System/Log folder
In a situation where I needed to do some logging in the Ecommerce checkout process I made this little method for populating different log areas.
using Dynamicweb.Logging;
public class MyAddIn {
//some logic here...
protected internal static void Log(string message, Exception ex = null)
{
Dynamicweb.Frontend.PageView.Current().Execution.Add("MyAddIn: " + message + ((ex != null) ? ex.Message : ""));
Dynamicweb.Ecommerce.Orders.OrderDebuggingInfo.Save(Dynamicweb.Ecommerce.Common.Context.Cart, message + " - " + ((ex != null) ? ex.Message : ""), "MyAddIn");
if (ex != null)
{
LogManager.Current.GetLogger("MyAddIn").Error(message, ex);
LogManager.System.GetLogger("Health", "Checkout").Error(message, ex);
}
else
{
LogManager.Current.GetLogger("MyAddIn").Info(message);
LogManager.System.GetLogger("Health", "Checkout").Info(message);
}
}
}
You may not need all the logging approaches, but you never know until you wish you had it ;-)