Inject ILogger to custom class implement IAuditingStore
See original GitHub issueI create a custom class AuditGrayLogStore to implement IAuditingStore by replace in PreInitialize module:
Configuration.ReplaceService(typeof(IAuditingStore), () =>
{
IocManager.Register<IAuditingStore, AuditGrayLogStore>(DependencyLifeStyle.Transient);
});
I success log to DB when use this code for AuditGrayLogStore:
using System.Threading.Tasks;
using Abp.Auditing;
using Abp.Dependency;
using Abp.Domain.Repositories;
using Microsoft.Extensions.Logging;
namespace ICO.AuditGrayLog
{
public class AuditGrayLogStore : IAuditingStore, ITransientDependency
{
private readonly IIocResolver _iocResolver;
private readonly IRepository<AuditLog, long> _auditLogRepository;
/// <summary>
/// Creates a new <see cref="AuditingStore"/>.
/// </summary>
public AuditGrayLogStore(
IRepository<AuditLog, long> auditLogRepository
)
{
_auditLogRepository = auditLogRepository;
}
public virtual Task SaveAsync(AuditInfo auditInfo)
{
return _auditLogRepository.InsertAsync(AuditLog.CreateFromAuditInfo(auditInfo));
}
}
}
But when I inject ILogger like this code:
using System.Threading.Tasks;
using Abp.Auditing;
using Abp.Dependency;
using Abp.Domain.Repositories;
using Microsoft.Extensions.Logging;
namespace ICO.AuditGrayLog
{
public class AuditGrayLogStore : IAuditingStore, ITransientDependency
{
private readonly IIocResolver _iocResolver;
private readonly IRepository<AuditLog, long> _auditLogRepository;
/// <summary>
/// Creates a new <see cref="AuditingStore"/>.
/// </summary>
public AuditGrayLogStore(
IIocResolver iocResolver,
IRepository<AuditLog, long> auditLogRepository
)
{
_iocResolver = iocResolver;
_auditLogRepository = auditLogRepository;
}
public virtual Task SaveAsync(AuditInfo auditInfo)
{
using (var scope = _iocResolver.CreateScope())
{
var GrayLogger = scope.Resolve<ILogger>();
GrayLogger.LogError("GrayLogger");
}
return _auditLogRepository.InsertAsync(AuditLog.CreateFromAuditInfo(auditInfo));
}
}
}
Error is : Mvc.ExceptionHandling.AbpExceptionFilter - No component for supporting the service Microsoft.Extensions.Logging.ILogger was found
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
ILogger Injection into Class
ILogger is a logger that your code can use to write log messages. There are three core methods: IsEnabled tests whether a log...
Read more >Implement a custom logging provider - .NET
Discover how to implement a custom logging provider with colorized logs, writing custom C# ILogger and ILoggerProvider implementations.
Read more >Abp Auditing log on DB #242
If I create a custom class like on Abp.Zero "public class AuditingStore : IAuditingStore, ITransientDependency" how will I Fill my AuditInfo ...
Read more >Audit Logging | Documentation Center | ABP.IO
If you need to save the audit log objects to a custom data store, you can implement the IAuditingStore in your own application...
Read more >.NET Logging Guide: Part 4 - Custom Logging Providers - ...
In part 4 of the .NET Logging Guide series we break down custom loggers and how to build a logger that logs to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@maliming Thank you , i fixed by follow https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-2.2 when use:
public AuditGrayLogStore(ILogger<AuditGrayLogStore> logger)
Don’t forget to add the “using Abp.Configuration.Startup;” statement since the Configuration.ReplaceService extension method is defined in that namespace.
“i want use this class: Microsoft.Extensions.Logging;” please see: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-2.2