예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FileAppenderLogger"/> class.
        /// </summary>
        /// <param name="fileName">File name to append log entries to.</param>
        /// <param name="asyncHandler">Asynchronous handler for logs processing.</param>
        /// <param name="serializerSource">The serializer source.</param>
        public FileAppenderLogger(
            string fileName,
            IAsyncHandler asyncHandler,
            IJsonSerializerSource serializerSource = null)
        {
            // ReSharper disable JoinNullCheckWithUsage
            if (fileName == null)
            {
                throw new ArgumentNullException(nameof(fileName));
            }

            if (asyncHandler == null)
            {
                throw new ArgumentNullException(nameof(asyncHandler));
            }

            string directoryName = Path.GetDirectoryName(fileName);

            if (!Directory.Exists(directoryName))
            {
                Directory.CreateDirectory(directoryName);
            }

            // ReSharper restore JoinNullCheckWithUsage
            _fileName        = fileName;
            AsyncHandler     = asyncHandler;
            SerializerSource = serializerSource ?? StdJsonLogging.DefaultSerializerSource;
            if (SerializerSource.Settings.Formatting != Formatting.None)
            {
                throw new NotSupportedException("Serialized json strings should be formatted in a one line.");
            }
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NUnitJsonLogger"/> class.
        /// </summary>
        /// <param name="asyncHandler">Asynchronous log write handler.</param>
        /// <param name="serializerSource">The serializer source.</param>
        public NUnitJsonLogger(
            IAsyncHandler asyncHandler,
            IJsonSerializerSource serializerSource = null)
        {
            if (asyncHandler == null)
            {
                throw new ArgumentNullException(nameof(asyncHandler));
            }

            AsyncHandler = asyncHandler;

            SerializerSource = serializerSource ?? StdJsonLogging.DefaultSerializerSource;

            _localZone = DateTimeZoneProviders.Tzdb.GetSystemDefault();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DelegateLogEntryBuilderForLogEntry"/> class.
        /// </summary>
        /// <param name="buildDelegate">Delegates that builds entry.</param>
        /// <param name="serializerSource">The serializer source.</param>
        public DelegateLogEntryBuilderForLogEntry(
            Func <LogEntry, LogEntry> buildDelegate,
            IJsonSerializerSource serializerSource)
        {
            if (buildDelegate == null)
            {
                throw new ArgumentNullException(nameof(buildDelegate));
            }

            if (serializerSource == null)
            {
                throw new ArgumentNullException(nameof(serializerSource));
            }

            _buildDelegate   = buildDelegate;
            SerializerSource = serializerSource;
        }
예제 #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ConsoleJsonLogger"/> class.
        /// </summary>
        /// <param name="asyncHandler">Asynchronous log write handler.</param>
        /// <param name="serializerSource">Logging serializer. Used to convert objects to strings and to JObject.</param>
        /// <param name="maxSeverity">Maximal visible severity.</param>
        public ConsoleJsonLogger(
            IAsyncHandler asyncHandler,
            IJsonSerializerSource serializerSource = null,
            LogSeverity maxSeverity = LogSeverity.Debug)
        {
            _maxSeverity = maxSeverity;
            if (asyncHandler == null)
            {
                throw new ArgumentNullException(nameof(asyncHandler));
            }

            AsyncHandler = asyncHandler;

            SerializerSource = serializerSource ?? StdJsonLogging.DefaultSerializerSource;

            _localZone = DateTimeZoneProviders.Tzdb.GetSystemDefault();
        }
예제 #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TextJsonLogger"/> class.
        /// </summary>
        /// <param name="asyncHandler">Asynchronous log write handler.</param>
        /// <param name="writeAction">Action that performs entry write operation.</param>
        /// <param name="serializerSource">The serializer source.</param>
        public TextJsonLogger(
            IAsyncHandler asyncHandler,
            Action <string> writeAction,
            IJsonSerializerSource serializerSource = null)
        {
            if (asyncHandler == null)
            {
                throw new ArgumentNullException(nameof(asyncHandler));
            }

            if (writeAction == null)
            {
                throw new ArgumentNullException(nameof(writeAction));
            }

            _writeAction     = writeAction;
            AsyncHandler     = asyncHandler;
            SerializerSource = serializerSource
                               ?? new JsonSerializerSource(
                () => StdJsonLogging.DefaultSerializerSource.CreateSettings());

            _localZone = DateTimeZoneProviders.Tzdb.GetSystemDefault();
        }