Writing from code to Log

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
Hace 11 años
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!
Hace 11 años
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'.
Hace 11 años
Hi Andrei,

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

Thx!
Hace 11 años
Have a look at \src\Libraries\Nop.Services\Orders\OrderProcessingService.cs. ILogger is injected via contructor and used when required
Hace 11 años
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);
Hace 11 años
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.