0
ivanosw1 created
Hi, I would like to log same informations when my Worker is initialized, like parameters, options and so on. This is my ctor. The call to repository works, but the Logger doesn't write nothing. On DoWork method the Logger works.
public class IntegrationWorker : PeriodicBackgroundWorkerBase, ISingletonDependency
....
public IntegrationWorker(AbpTimer timer,
IRepository<ConfigurationData> configurationRepository) : base(timer)
{
_impostazioniRepository = impostazioniRepository;
var periodData = _impostazioniRepository.FirstOrDefault(p => p.Parametro == "Polling");
var period = periodData == null ? 15000 : int.Parse(periodData.Value);
Logger.InfoFormat("Integration worker loaded with Period of {0} milliseconds", period);
timer.Period = Period;
}
Is possibile to log on constructor ?
Thank you.
3 Answer(s)
-
0
Logger come from base class and it is the property of base class. Property injection runs after class constructor method. If you inject the logger class to constructor as parameter, you can use it. I mean something like following:
public IntegrationWorker(ILogger logger, AbpTimer timer, IRepository<ConfigurationData> configurationRepository) : base(timer)
-
0
Thank you. Your suggestion works.
I've two different varibales that refers to the same logger, but in this particulare case I can survive with this.
-
0
good to hear it works ;)