示例#1
0
        /// <summary>
        /// Constructs a new instance of this class
        /// </summary>
        /// <param name="caller">The object that is doing the logging</param>
        /// <param name="messageBus">A message bus to send log messages over</param>
        /// <param name="logEntryRepository">An IRepository implememntation for persisting logged messages</param>
        /// <param name="errorRepository">An IRepository implementation for persisting errors</param>
        public Logger(object caller, MessageBus messageBus, IRepository <LogEntry> logEntryRepository, IRepository <AuditableError> errorRepository)
        {
            Contract.Requires(logEntryRepository != null);
            Contract.Requires(caller != null);

            this.SessionStart       = DateTime.Now;
            this.GUID               = Guid.NewGuid().ToString();
            this.Caller             = caller.GetType().ToString();
            this.Entries            = new List <LogEntry>();
            this.MessageBus         = messageBus;
            this.LogEntryRepository = logEntryRepository;
            this.ErrorRepository    = errorRepository;
            this.FileName           = $"Logs\\{Caller}.{SessionStart.ToString("yyyy.MM.dd.HH.mm.ss", CultureInfo.CurrentCulture)}.log";

            if (!Directory.Exists("Logs"))
            {
                Directory.CreateDirectory("Logs");
            }

            WriteContext = logEntryRepository.WriteContext();
        }
 public string ToSessionString()
 {
     return($"{Guid}_{SessionStart.ToString()}");
 }