Exemplo n.º 1
0
        /// <summary>
        /// Constructor
        /// </summary>
        public FileLogger(JobSettings jobSettings) : base(jobSettings)
        {
            JobSettings = jobSettings;

            var loggerConfiguration = new LoggerConfiguration()
                                      .WriteTo.Console(Serilog.Events.LogEventLevel.Error)
                                      .WriteTo.File($"{jobSettings.RunId}.log");

            if (LogLevel == LogLevel.Verbose)
            {
                loggerConfiguration.MinimumLevel.Verbose();
            }
            else if (LogLevel == LogLevel.Information)
            {
                loggerConfiguration.MinimumLevel.Information();
            }
            else if (LogLevel == LogLevel.ErrorsAndSuccess)
            {
                loggerConfiguration.MinimumLevel.Warning();
            }
            else if (LogLevel == LogLevel.ErrorsOnly)
            {
                loggerConfiguration.MinimumLevel.Error();
            }
            Log.Logger = loggerConfiguration.CreateLogger();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Define context properties based on configuration for App Insights logging
        /// </summary>
        /// <returns></returns>
        public static Dictionary <string, string> GetContextProperties(JobSettings jobSettings)
        {
            var contextProperties = new Dictionary <string, string>()
            {
                { "Context.Crm.ConnectionString", jobSettings.CrmConnectionString },
                { "Context.Crm.Instance.Name", jobSettings.SelectedInstanceName },
                { "Context.Crm.User.Name", jobSettings.CrmUserName },
                { "Context.Job.Name", jobSettings.SelectedJobName },
                { "Context.Job.Run.Id", jobSettings.RunId },

                { "Context.Process.Version", Version.VersionNumber },
                { "Context.Process.MaxDuration.Hours", jobSettings.MaxRunDurationInHour.ToString() },
                { "Context.Process.Query.RecordLimit", jobSettings.QueryRecordLimit.ToString() },
                { "Context.Process.Thread.Number", jobSettings.ThreadNumber.ToString() },

                { "Context.Logging.Level", jobSettings.LogLevel.ToString() },
                { "Context.Logging.AppInsight.Enabled", jobSettings.ApplicationInsightsEnabled.ToString() },
                { "Context.Logging.AppInsight.InstrumentationKey", jobSettings.AppInsightsInstrumentationKey },
                { "Context.Logging.Graylog.Enabled", jobSettings.GrayLogEnabled.ToString() },
                { "Context.Logging.Graylog.Url", jobSettings.GrayLogUrl },

                { "Context.Computer.name", Environment.MachineName },
                { "Context.Computer.OS.Version", Environment.OSVersion.Version.ToString() },
                { "Context.Computer.Local.Username", Environment.UserName },
                { "Context.Computer.CurrentDirectory", Environment.CurrentDirectory }
            };

            if (jobSettings.JobNamesDefined)
            {
                contextProperties.Add("Job.Names", jobSettings.JobNames);
            }

            return(contextProperties);
        }
        public BaseLogger(JobSettings jobSettings)
        {
            JobSettings = jobSettings;

            try
            {
                LogLevel = (LogLevel)Enum.Parse(typeof(LogLevel), JobSettings.LogLevel.ToString());
            }
            catch
            {
                throw new Exception($"Incorrect log level in configuration! (value = '{JobSettings.LogLevel.ToString()}')");
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Show context information in console
        /// </summary>
        /// <param name="jobSettings"></param>
        /// <param name="runId"></param>
        /// <param name="logger"></param>
        public static void OutputContextInformation(JobSettings jobSettings, ILogger logger)
        {
            var contextProperties = GetContextProperties(jobSettings);

            logger.LogDisplay($"Job parameters : ");
            foreach (var property in contextProperties)
            {
                var key = property.Key;
                key = key.Replace("Context", "");
                key = key.Replace(".", " ");
                logger.LogDisplay($" - {key} : {property.Value}");
            }
            logger.LogDisplay("");
        }
        /// <summary>
        /// Retrieve all datajob class instances with IsEnabled = true
        /// </summary>
        /// <param name="jobSettings"></param>
        /// <returns></returns>
        public static List <DataJobBase> GetDataJobs(JobSettings jobSettings, JobProcessParameters parameters)
        {
            var dataJobs       = new List <DataJobBase>();
            var dataJobClasses = Assembly.GetEntryAssembly().GetTypes().Where(t => typeof(DataJobBase).IsAssignableFrom(t) && !t.IsAbstract);

            foreach (var dataJobClass in dataJobClasses)
            {
                var constructor     = dataJobClass.GetConstructor(new Type[] { typeof(JobSettings), typeof(JobProcessParameters) });
                var dataJobInstance = constructor?.Invoke(new object[] { jobSettings, parameters }) as DataJobBase;
                if (dataJobInstance?.IsEnabled == true)
                {
                    dataJobs.Add(dataJobInstance);
                }
            }
            return(dataJobs);
        }
        public ProcessorBase()
        {
            JobSettings = new JobSettings();
            if (JobSettings.ApplicationInsightsEnabled)
            {
                Logger = new ApplicationInsightLogger(JobSettings);
            }
            else if (JobSettings.GrayLogEnabled)
            {
                Logger = new GrayLogger(JobSettings);
            }
            else
            {
                Logger = new FileLogger(JobSettings);
            }
            ConsoleHelper = new ConsoleHelper(Logger);

            Utilities.OutputContextInformation(JobSettings, Logger);
        }
 /// <summary>
 /// Constructor
 /// </summary>
 public ApplicationInsightLogger(JobSettings jobSettings) : base(jobSettings)
 {
     JobSettings = jobSettings;
     InitializeClient();
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="jobSettings"></param>
 public FullProcessDataJobBase(JobSettings jobSettings, JobProcessParameters parameters) : base(jobSettings, parameters)
 {
 }
Exemplo n.º 9
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="jobSettings"></param>
 public InputFileProcessDataJobBase(JobSettings jobSettings, JobProcessParameters parameters) : base(jobSettings, parameters)
 {
 }
 /// <summary>
 /// Constructor
 /// </summary>
 public GrayLogger(JobSettings jobSettings) : base(jobSettings)
 {
     JobSettings = jobSettings;
     InitializeClient();
 }