Writing from code to Log

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
11 лет назад
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!
11 лет назад
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'.
11 лет назад
Hi Andrei,

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

Thx!
11 лет назад
Have a look at \src\Libraries\Nop.Services\Orders\OrderProcessingService.cs. ILogger is injected via contructor and used when required
11 лет назад
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);
11 лет назад
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.