Writing from code to Log

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
Il y a 11 ans
If I want to write a simple message to the Log regarding a user action, what is the (best) way to do so?
Should I use the 'DefaultLogger' or the 'CustomerActivityService'? And, more important, how? :)

Thanks in advance!
Il y a 11 ans
If you want to write to log (usually exceptions and errors), use 'ILogger/DefaultLogger'. If you want to write to an user activity (usually information such as "viewing a category", etc), use 'ICustomerActivityService'.
Il y a 11 ans
Hi Andrei,

Thanks for the quick reply. Could you please provide me with an example of the DefaultLogger service?

Thx!
Il y a 11 ans
Have a look at \src\Libraries\Nop.Services\Orders\OrderProcessingService.cs. ILogger is injected via contructor and used when required
Il y a 11 ans
Something like this?


Nop.Services.Logging.DefaultLogger logger = (Nop.Services.Logging.DefaultLogger)Nop.Core.Infrastructure.EngineContext.Current.Resolve<Nop.Services.Logging.ILogger>();
logger.InsertLog(Nop.Core.Domain.Logging.LogLevel.Information, "Customer doing something!", "Customer ......", null);
Il y a 11 ans
Yes. You can do it this way. But it's not very elegant. See my best above for more proper way of getting ILogger instance
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.