Developer Blog

Logging

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 ;-)

Comments
 
Nuno Aguiar
Nuno Aguiar
Dynamicweb North America, Inc
01 December 2021 at 14:05

Hi Lars,

 

This a a great summary, thank you. In terms of wishes, we wish we could send all logs to a different DB and file location when needed :) Is that doable?

 

We've had projects where logs grow so much we need to clean them every 2 or 3 months. This obviously shapes a few decisions/features such as personalization and/or marketing automation flows and whatnot.

 

 

Nuno Aguiar

 
Lars Hejgaard Sørensen
Lars Hejgaard Sørensen
Dynamicweb Software A/S
01 December 2021 at 16:58

Hi Nuno,

Everything is doable, but whether you want this to be done at runtime or in batches is a different matter:-) If the latter, it's just a matter of hard labour in setting up some synchronization, but if should be live, it is something to talk the product manager about :-)

Moving log data from the database to another database or server could easily be done with the Data Integration app, and then you can safely clean up the application log. We can't move files out of the box, but one idea could be to load them into the database. I made a small console app a while ago which populated the IIS log to a database table, because that is so much more convenient to deal with than the log files. The same could be done for other log files, and then these could also be moved with Data Integration. Or imagine loading them into the Lucene index from the database! Oh, what possibilities we would suddenly have with searching and filtering log entries ;-)

Br.
Lars

 

You must be logged in to comment