public Logger(string categoryName) { if (string.IsNullOrWhiteSpace(categoryName)) { categoryName = DefaultCategoryName; } CategoryName = categoryName; DataContainer = new LoggerDataContainer(this); }
internal void Reset() { HttpProperties httpProperties = DataContainer.HttpProperties; DataContainer.Dispose(); DataContainer = new LoggerDataContainer(this); if (httpProperties != null) { DataContainer.SetHttpProperties(httpProperties); } }
public void DisposeAlsoDisposesTheFilesContainer() { LoggerDataContainer loggerDataContainer = new LoggerDataContainer(new Logger()); bool disposedBefore = loggerDataContainer.FilesContainer._disposed; loggerDataContainer.Dispose(); bool disposedAfter = loggerDataContainer.FilesContainer._disposed; Assert.IsFalse(disposedBefore); Assert.IsTrue(disposedAfter); }
public void DisposeUpdatesTheDisposedField() { LoggerDataContainer loggerDataContainer = new LoggerDataContainer(new Logger()); bool disposedBefore = loggerDataContainer._disposed; loggerDataContainer.Dispose(); bool disposedAfter = loggerDataContainer._disposed; Assert.IsFalse(disposedBefore); Assert.IsTrue(disposedAfter); }
public void ResetCreatesANewLoggerDataContainer() { Logger logger = new Logger(); logger.Trace("Message"); logger.Error(new Exception()); logger.LogAsFile("My file"); LoggerDataContainer dataContainer1 = logger.DataContainer; logger.Reset(); LoggerDataContainer dataContainer2 = logger.DataContainer; Assert.AreNotSame(dataContainer1, dataContainer2); }
public void ResetClearsTheLoggerDataContainer() { Logger logger = new Logger(); logger.Trace("Message"); logger.Error(new Exception()); logger.LogAsFile("My file"); logger.Reset(); LoggerDataContainer dataContainer = logger.DataContainer; Assert.AreEqual(0, dataContainer.LogMessages.Count()); Assert.AreEqual(0, dataContainer.Exceptions.Count()); Assert.AreEqual(0, dataContainer.FilesContainer.GetLoggedFiles().Count); }
private static ArgsResult CreateArgs(Logger[] loggers) { Logger defaultLogger = loggers.FirstOrDefault(p => p.CategoryName == Logger.DefaultCategoryName) ?? loggers.First(); LoggerDataContainer dataContainer = defaultLogger.DataContainer; WebRequestProperties webRequestProperties = dataContainer.WebRequestProperties; string errorMessage = dataContainer.Exceptions.LastOrDefault()?.ExceptionMessage; List <LogMessagesGroup> logMessages = new List <LogMessagesGroup>(); List <CapturedException> exceptions = new List <CapturedException>(); foreach (Logger logger in loggers) { logMessages.Add(new LogMessagesGroup { CategoryName = logger.CategoryName, Messages = logger.DataContainer.LogMessages.ToList() }); exceptions.AddRange(logger.DataContainer.Exceptions); } exceptions = exceptions.Distinct(new CapturedExceptionComparer()).ToList(); if (defaultLogger.IsCreatedByHttpRequest() == false && exceptions.Any()) { webRequestProperties.Response.HttpStatusCode = System.Net.HttpStatusCode.InternalServerError; } List <LoggerFile> files = dataContainer.LoggerFiles.GetFiles().ToList(); FlushLogArgs args = new FlushLogArgs { IsCreatedByHttpRequest = defaultLogger.IsCreatedByHttpRequest(), WebRequestProperties = webRequestProperties, MessagesGroups = logMessages, CapturedExceptions = exceptions }; args.Files = files; return(new ArgsResult { Args = args, Files = files }); }
public void ResetDisposesTheOldDataContainerAndCreatesANewOne() { Logger logger = new Logger(); logger.Trace("Message"); logger.Error(new Exception()); logger.LogAsFile("My file"); LoggerDataContainer oldDataContainer = logger.DataContainer; logger.Reset(); LoggerDataContainer newDataContainer = logger.DataContainer; Assert.IsTrue(oldDataContainer._disposed); Assert.AreNotSame(oldDataContainer, newDataContainer); }
public Logger(string categoryName = null, string url = null) { Id = Guid.NewGuid(); CategoryName = string.IsNullOrWhiteSpace(categoryName) ? Constants.DefaultLoggerCategoryName : categoryName; DataContainer = new LoggerDataContainer(this); HttpProperties httpProperties = string.IsNullOrWhiteSpace(url) ? null : HttpPropertiesFactory.Create(url); if (httpProperties != null) { DataContainer.SetHttpProperties(httpProperties); InternalHelpers.WrapInTryCatch(() => { NotifyBeginRequest.Notify(httpProperties.Request); }); } }
public Logger(string categoryName = null, string url = null) { CategoryName = categoryName ?? DefaultCategoryName; DataContainer = new LoggerDataContainer(this); if (string.IsNullOrEmpty(url) == false) { Uri uri = GenerateUri(url); if (uri != null) { DataContainer.WebProperties.Request.Url = uri; // If the logger gets created with the url, we consider it as a BeginRequest event // this.DataContainer.AddProperty(KissLog.Internal.Constants.IsCreatedByHttpRequestProperty, true); KissLog.Internal.NotifyListeners.NotifyBeginRequest(DataContainer.WebProperties.Request, this); } } }
public void AddMessageThrowsExceptionForNullArgument() { LoggerDataContainer loggerDataContainer = new LoggerDataContainer(new Logger()); loggerDataContainer.Add((LogMessage)null); }
public void ExceptionsIsNotNull() { LoggerDataContainer loggerDataContainer = new LoggerDataContainer(new Logger()); Assert.IsNotNull(loggerDataContainer.Exceptions); }
public void AddExceptionThrowsExceptionForNullArgument() { LoggerDataContainer loggerDataContainer = new LoggerDataContainer(new Logger()); loggerDataContainer.Add((Exception)null); }
public void SetHttpPropertiesThrowsExceptionForNullArgument() { LoggerDataContainer loggerDataContainer = new LoggerDataContainer(new Logger()); loggerDataContainer.SetHttpProperties(null); }
public void NullLoggerThrowsException() { LoggerDataContainer loggerDataContainer = new LoggerDataContainer(null); }
public void StartDateTimeHasValue() { LoggerDataContainer loggerDataContainer = new LoggerDataContainer(new Logger()); Assert.IsTrue(loggerDataContainer.DateTimeCreated.Year > default(DateTime).Year); }
public void StartDateTimeIsInThePast() { LoggerDataContainer loggerDataContainer = new LoggerDataContainer(new Logger()); Assert.IsTrue(loggerDataContainer.DateTimeCreated < DateTime.UtcNow); }
public void StartDateTimeIsInUtcFormat() { LoggerDataContainer loggerDataContainer = new LoggerDataContainer(new Logger()); Assert.AreEqual(DateTimeKind.Utc, loggerDataContainer.DateTimeCreated.Kind); }
public void LoggerPropertiesIsNotNull() { LoggerDataContainer loggerDataContainer = new LoggerDataContainer(new Logger()); Assert.IsNotNull(loggerDataContainer.LoggerProperties); }
public void FilesContainerIsNotNull() { LoggerDataContainer loggerDataContainer = new LoggerDataContainer(new Logger()); Assert.IsNotNull(loggerDataContainer.FilesContainer); }