using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace Edge.Core.UniversalApi.Auditing
{
    internal class SimpleLogAuditingStore : IAuditingStore
    {
        private ILogger logger;

        internal SimpleLogAuditingStore(IServiceProvider services)
        {
            var loggerFactory = services.GetRequiredService<ILoggerFactory>();
            this.logger = loggerFactory.CreateLogger("UniversalApiAuditing");
        }

        public Task SaveAsync(AuditLogInfo auditInfo)
        {
            if (this.logger.IsEnabled(LogLevel.Information))
                this.logger.LogInformation(auditInfo.ToString());
            return Task.FromResult(0);
        }
    }
}
