November Happy Hour will be moved to Thursday December 5th.

Logging/tracing Commerce import

Vote:
 

Hi Forum

Is there a way to setup logging/tracing so that I can get some insight into how Commerce is importing data using catalog.xml files?

I have been able to do this in an earlier version of Optimizely Commerce, I believe that was with the Log4Net setup. Can I still do this with the new Logging API?

I have tried to enable Debug logging on "Episerver" and "Mediachase" but I don't see anything interresting in my logfiles. So either I'm doing something wrong, or the possibility to get this insight is gone?

#326717
Aug 08, 2024 6:41
Manoj Kumawat - Aug 09, 2024 10:25
I use Serilog with an upgraded systems and it all works fine. Let me know if this is something you have not tried.
Vote:
 

Hi Manoj Kumawat

Thank you for your reply. That sounds promising, since we are also using Serilog. So it must be due to some misconfiguration on my part.

Can you provide insight into which loging sources and LogLevels you have configured to get good insight into the commerce import process?

Can you also provide examples of log statements that you can see in your log, so I can try to see if I can duplicate this?

Thank you very much for your help.

Regards

Anders

#326768
Aug 09, 2024 10:31
Vote:
 

Hello Anders, I will try to explain steps included in setup for Serilog. I am sure you might have something similar to it.
 
Appsettings.json - We have set it to Level Warning on Production and writing it to both console and file.

"Serilog": {
        "Using": [],
        "MinimumLevel": {
            "Default": "Warning",
            "Override": {
                "Microsoft": "Warning",
                "System": "Warning"
            }
        },
        "Enrich": [
            "FromLogContext",
            "WithMachineName",
            "WithProcessId",
            "WithThreadId"
        ],
        "WriteTo": [
            {
                "Name": "Console"
            },
            {
                "Name": "File",
                "Args": {
                    "path": "App_Data/EPiServerErrors.log.txt",
                    "rollingInterval": "Day",
                    "outputTemplate": "{Timestamp:G} {Message}{NewLine:1}{Exception:1}"
                }
            }
        ]
    }

Program.cs - reading if from context file. e.g. appsettings.{env}.json

 public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .ConfigureCmsDefaults()
            .UseSerilog(
                (context, configuration) => { configuration.ReadFrom.Configuration(context.Configuration); })
            .ConfigureAppConfiguration((ctx, builder) => { builder.AddConfiguration(Configuration); })
            .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); });

Logging it in a service (example usage)

using Serilog;

namespace Test.EpiServer.Controllers;

public class TestController : ControllerBase
{
    private readonly ILogger _logger;

    public TestController()
    {
        _logger = Log.ForContext(typeof(TestController));
    }


    public void TestResults()
    {
		_logger.Error("Logging Error in TestMethod called.");
    }
}

I might have missed some references to include but this is what it basically did for us.

#326769
Edited, Aug 09, 2024 10:49
Vote:
 

Hi,

Did you try to set log level in appSettings.json like this:

I think it should work by default

#326815
Aug 10, 2024 10:46
Vote:
 

Hi Manoj and Binh

Thank you for your help.

I will take a look at my configuration again and try to do some tests. It must be something that I haven't configured properly.

#326886
Aug 12, 2024 5:11
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.