Exemplo n.º 1
0
        public ScopeWriter(
            ITestOutputHelper outputHelper,
            object?state,
            int depth,
            Action onScopeEnd,
            LoggingConfig config)
        {
            _outputHelper = outputHelper;
            _state        = state;
            _depth        = depth;
            _onScopeEnd   = onScopeEnd;
            _config       = config;

            DetermineScopeStateMessage();

            var scopeStartMessage = BuildScopeStateMessage(false);

            _outputHelper.WriteLine(scopeStartMessage);

            if (string.IsNullOrWhiteSpace(_structuredStateData) == false)
            {
                var padding = BuildPadding(_depth + 1);

                // Add the padding to the structured data
                var structuredLines =
                    _structuredStateData.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);

                var structuredData = padding + string.Join(Environment.NewLine + padding, structuredLines);

                _outputHelper.WriteLine("{0}{1}{2}{3}", padding, "Scope data: ", Environment.NewLine, structuredData);
            }
        }
        public ScopeWriter(
            ITestOutputHelper output,
            object?state,
            int depth,
            string category,
            Action onScopeEnd,
            LoggingConfig config)
        {
            _output     = output;
            _state      = state;
            _depth      = depth;
            _category   = category;
            _onScopeEnd = onScopeEnd;
            _config     = config;

            DetermineScopeStateMessage();

            var scopeStartMessage = BuildScopeStateMessage(false);

            WriteLog(_depth, scopeStartMessage);

            if (string.IsNullOrWhiteSpace(_structuredStateData) == false)
            {
                // Add the padding to the structured data
                var structuredLines =
                    _structuredStateData.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);

                WriteLog(_depth + 1, "Scope data: ");

                foreach (var structuredLine in structuredLines)
                {
                    WriteLog(_depth + 1, structuredLine);
                }
            }
        }
        /// <summary>
        ///     Creates a new instance of the <see cref="TestOutputLogger" /> class.
        /// </summary>
        /// <param name="categoryName">The category name of the logger.</param>
        /// <param name="output">The test output helper.</param>
        /// <param name="config">Optional logging configuration.</param>
        /// <exception cref="ArgumentException">The <paramref name="categoryName" /> is <c>null</c>, empty or whitespace.</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="output" /> is <c>null</c>.</exception>
        public TestOutputLogger(string categoryName, ITestOutputHelper output, LoggingConfig?config = null)
        {
            if (string.IsNullOrWhiteSpace(categoryName))
            {
                throw new ArgumentException("No name value has been supplied", nameof(categoryName));
            }

            _categoryName = categoryName;
            _output       = output ?? throw new ArgumentNullException(nameof(output));
            _config       = config ?? new LoggingConfig();
        }
 /// <summary>
 ///     Initializes a new instance of the <see cref="DefaultFormatter" /> class.
 /// </summary>
 /// <param name="config">The logging configuration.</param>
 /// <exception cref="ArgumentNullException">The <paramref name="config" /> value is <c>null</c>.</exception>
 public DefaultFormatter(LoggingConfig config)
 {
     _config = config ?? throw new ArgumentNullException(nameof(config));
 }