Hi,
why Logger does not log when use it with classes other than app service classes, can any one tell me where is the error here:
//SomeClass.cs
public class SomeClass : ITransientDependency
{
public ILogger Logger { get; set; }
public SomeClass ()
{
Logger = NullLogger.Instance;
}
internal async Task SomeMethod()
{
//.................
//log message does not work
Logger.Info("message");
//..............
}
}
//DemoApplicationModule.cs
[DependsOn(typeof(DemoCoreModule))]
public class DemoApplicationModule : AbpModule
{
public override void Initialize()
{
IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());
IocManager.Resolve<SomeClass>();
}
}
8 Answer(s)
-
0
It works everywhere, not only app services.
SomeClass is correct but where did you call SomeMethod() ? I did not see it.
-
0
Hi Halil, thanks for reply. I call somemethod from my app services:
public class someAppService : ApplicationService, ISomeAppService { private readonly SomeController _someController; public Task SomeAction() { //........... _someController.SomeMethod(); // ............ }
-
0
All code at somemethod() executed normally except logging and if I call logger inside someAppService it works and i can see the loggs.
one another question, How can I implement custom action filters on someAppService like apbAuthorize ?
-
0
Hi,
You can create an attribute and an Castle Windsor interceptor which checks and executes it. ABP highly uses interceptors.
-
0
Ok, How about Logging :), Am I missing something?
-
0
Can you check if Logger is NullLogger? Maybe somehow DI not working in your case. But sure that Logger is not a special thing and works in every class.
-
0
Yes, It is NullLogger, but WHY :o ? I tried calling the Logger directly after resolving in DemoApplicationModule.cs and it works:
//DemoApplicationModule.Initialize() //... var someObj = IocManager.Resolve<SomeClass>(); someObj.Logger.Info("Testing...");//it works here someObj.SomeMethod();//this logs also... //...
-
0
Actually, I want to tell you that it works in every class :D. Many thanks Halil.