<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;

namespace Digithought.Framework
{
	public static class Logging
	{
		public static event Action<Exception> LogError;
		public static event Action<string, object> LogTrace;
		public static Func<string, object, bool> TraceFilter;

		public static void Error(Exception e)
		{
			var handler = LogError;
			if (handler != null)
				handler(e);
			else
				System.Diagnostics.Trace.WriteLine(DateTime.Now.ToString("o") + ": " + e.ToString());
		}

		/// <summary> Logs a trace message. </summary>
		/// <param name="category"> Use LoggingCategory class for valid categories. </param>
		/// <param name="message"> Message.  Don't include timestamp. </param>
		[System.Diagnostics.Conditional("FRAMEWORK_TRACING")]
		public static void Trace(string category, object message)
		{
			// Filter as appropriate
			var pass = true;
			var filter = TraceFilter;
			if (filter != null)
				pass = filter(category, message);

			if (pass)
			{
				System.Diagnostics.Trace.WriteLine(DateTime.Now.ToString("o") + ": " + message);

				var handler = LogTrace;
				if (handler != null)
					handler(category, message);
			}
		}
	}
}<commit_msg>Added proper delegates and Regex based category masking to logging utility.<commit_after>﻿using System;

namespace Digithought.Framework
{
    public static class Logging
	{
		public static event LogErrorHandler LogError;
		public static event LogTraceHandler LogTrace;
		public static LogTraceFilterHandler TraceFilter;
		public static System.Text.RegularExpressions.Regex CategoryMask = null;

		public static void Error(Exception e)
		{
			var handler = LogError;	// Capture
			if (handler != null)
				handler(e);
			else
				System.Diagnostics.Trace.WriteLine(DateTime.Now.ToString("o") + ": " + e.ToString());
		}

		/// <summary> Logs a trace message. </summary>
		/// <param name="category"> Use LoggingCategory class for valid categories. </param>
		/// <param name="message"> Message.  Don't include timestamp. </param>
		[System.Diagnostics.Conditional("FRAMEWORK_TRACING")]
		public static void Trace(string category, object message)
		{
			// Filter as appropriate
			var filter = TraceFilter;	// Capture
			var mask = CategoryMask;	// Capture
			if 
			(
				(filter == null || filter(category, message))
					&& (mask == null || mask.IsMatch(category))
			)
			{
				System.Diagnostics.Trace.WriteLine(DateTime.Now.ToString("o") + ": " + message);

				var handler = LogTrace;	// Capture
				if (handler != null)
					handler(category, message);
			}
		}
	}

	public delegate void LogErrorHandler(Exception e);

	public delegate void LogTraceHandler(string category, object message);

	public delegate bool LogTraceFilterHandler(string category, object message);
}
{'fraction_non_alphanumeric': 0.11779271312345242, 'fraction_numerical': 0.0, 'mean_word_length': 3.768971332209106, 'pattern_counts': {'":': 4, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '4398609', 'n_tokens_mistral': 924, 'n_tokens_neox': 797, 'n_words': 235}