<commit_before>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Reflection;
using System.Text;
using System.Xml;

using Log2Console.Log;

namespace Log2Console.Receiver
{
  public static class ReceiverUtils
  {
    static readonly DateTime s1970 = new DateTime(1970, 1, 1);

    public static string GetTypeDescription(Type type)
    {
      var attr = (DisplayNameAttribute)Attribute.GetCustomAttribute(type, typeof(DisplayNameAttribute), true);
      return attr != null ? attr.DisplayName : type.ToString();
    }

    /// <summary>
    /// We can share settings to improve performance
    /// </summary>
    static readonly XmlReaderSettings XmlSettings = CreateSettings();

    static XmlReaderSettings CreateSettings()
    {
      return new XmlReaderSettings { CloseInput = false, ValidationType = ValidationType.None };
    }

    /// <summary>
    /// We can share parser context to improve performance
    /// </summary>
    static readonly XmlParserContext XmlContext = CreateContext();

    static XmlParserContext CreateContext()
    {
      var nt = new NameTable();
      var nsmanager = new XmlNamespaceManager(nt);
      nsmanager.AddNamespace("log4j", "http://jakarta.apache.org/log4j/");
      return new XmlParserContext(nt, nsmanager, "elem", XmlSpace.None, Encoding.UTF8);
    }

    /// <summary>
    /// Parse LOG4JXml from xml stream
    /// </summary>
    public static LogMessage ParseLog4JXmlLogEvent(Stream logStream, string defaultLogger)
    {
      using (var reader = XmlReader.Create(logStream, XmlSettings, XmlContext))
        return ParseLog4JXmlLogEvent(reader, defaultLogger);
    }
<commit_msg>TcpReceiver ungraceful shutdown fix<commit_after>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Reflection;
using System.Text;
using System.Xml;

using Log2Console.Log;

namespace Log2Console.Receiver
{
  public static class ReceiverUtils
  {
    static readonly DateTime s1970 = new DateTime(1970, 1, 1);

    public static string GetTypeDescription(Type type)
    {
      var attr = (DisplayNameAttribute)Attribute.GetCustomAttribute(type, typeof(DisplayNameAttribute), true);
      return attr != null ? attr.DisplayName : type.ToString();
    }

    /// <summary>
    /// We can share settings to improve performance
    /// </summary>
    static readonly XmlReaderSettings XmlSettings = CreateSettings();

    static XmlReaderSettings CreateSettings()
    {
      return new XmlReaderSettings { CloseInput = false, ValidationType = ValidationType.None };
    }

    /// <summary>
    /// We can share parser context to improve performance
    /// </summary>
    static readonly XmlParserContext XmlContext = CreateContext();

    static XmlParserContext CreateContext()
    {
      var nt = new NameTable();
      var nsmanager = new XmlNamespaceManager(nt);
      nsmanager.AddNamespace("log4j", "http://jakarta.apache.org/log4j/");
      return new XmlParserContext(nt, nsmanager, "elem", XmlSpace.None, Encoding.UTF8);
    }

    /// <summary>
    /// Parse LOG4JXml from xml stream
    /// </summary>
    public static LogMessage ParseLog4JXmlLogEvent(Stream logStream, string defaultLogger)
    {
      using (var reader = XmlReader.Create(logStream, XmlSettings, XmlContext))
        return ParseLog4JXmlLogEvent(reader, defaultLogger, "");
    }

{'fraction_non_alphanumeric': 0.10052754982415006, 'fraction_numerical': 0.010550996483001172, 'mean_word_length': 3.496706192358366, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '966908', 'n_tokens_mistral': 961, 'n_tokens_neox': 902, 'n_words': 257}