Exemple #1
0
 public EasyAuditor(string source, LoggerDbContext context)
 {
     _config = new ApenLoggerConfiguration
     {
         SourceName    = source,
         LogRepository = LogRepository.Database
     };
     _culture = new CultureInfo("en-US");
     _context = context;
 }
Exemple #2
0
        public EasyAuditor(ApenLoggerConfiguration config, LoggerDbContext context)
        {
            switch (config.LogRepository)
            {
            case LogRepository.Database:
                if (context == null)
                {
                    throw new MissingFieldException("Apply the DbContext inorder to be able to use the database logging option.");
                }
                _context = context;
                break;

            case LogRepository.WindowsEvents:
                if (string.IsNullOrEmpty(config.SourceName))
                {
                    throw new MissingFieldException("SourceName cannot be null when Windows Events Logging is selected.");
                }
                break;

            case LogRepository.File:
                if (config.FileLogOption == null)
                {
                    config.FileLogOption = new FileLogOption();
                }
                if (string.IsNullOrEmpty(config.FileLogOption.FilePath))
                {
                    throw new MissingFieldException("FileLogOption cannot be null when File Logging is selected.");
                }
                if (!Directory.Exists(config.FileLogOption.FilePath))
                {
                    Directory.CreateDirectory(config.FileLogOption.FilePath);
                }
                break;

            default:
                break;
            }

            _culture = new CultureInfo("en-US");
            _config  = config;
        }