<commit_before>﻿using RSG.Utils;
using Serilog.Core;
using Serilog.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RSG
{
    /// <summary>
    /// Adds extra details to log messages.
    /// </summary>
    public class RSGLogEnricher : ILogEventEnricher
    {
        /// <summary>
        /// Interface that configures the app.
        /// </summary>
        private IAppConfigurator appConfigurator;

        public RSGLogEnricher(IAppConfigurator appConfigurator)
        {
            this.appConfigurator = appConfigurator;
        }

        public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
        {
            logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("UserName", Environment.UserName));
            logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("MachineName", Environment.MachineName));
            logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("AppInstanceID", App.AppInstanceID));
            logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("DeviceID", App.DeviceID));
            logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("AppMajorVersion", appConfigurator.MajorVersionNumber));
            logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("AppMinorVersion", appConfigurator.MinorVersionNumber));
        }
    }
}<commit_msg>Now conditionally attaching device name to each log if the device name was set by the application.<commit_after>﻿using RSG.Utils;
using Serilog.Core;
using Serilog.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RSG
{
    /// <summary>
    /// Adds extra details to log messages.
    /// </summary>
    public class RSGLogEnricher : ILogEventEnricher
    {
        /// <summary>
        /// Interface that configures the app.
        /// </summary>
        private IAppConfigurator appConfigurator;

        public RSGLogEnricher(IAppConfigurator appConfigurator)
        {
            this.appConfigurator = appConfigurator;
        }

        public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
        {
            logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("UserName", Environment.UserName));
            logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("MachineName", Environment.MachineName));
            logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("AppInstanceID", App.AppInstanceID));
            logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("DeviceID", App.DeviceID));
            if (string.IsNullOrEmpty(App.DeviceName))
            {
                logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("DeviceName", App.DeviceName));
            }
            
            logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("AppMajorVersion", appConfigurator.MajorVersionNumber));
            logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("AppMinorVersion", appConfigurator.MinorVersionNumber));
        }
    }
}
{'fraction_non_alphanumeric': 0.09114249037227215, 'fraction_numerical': 0.0, 'mean_word_length': 3.3052486187845305, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '6671812', 'n_tokens_mistral': 828, 'n_tokens_neox': 817, 'n_words': 142}