示例#1
0
        /// <summary>
        /// Log to the specified status level by using the status event on the corpus context (if it exists) or to the default logger.
        /// The log level, className, message and path values are also added as part of a new entry to the log recorder.
        /// </summary>
        /// <param name="level">The status level to log to.</param>
        /// <param name="ctx">The CDM corpus context.</param>
        /// <param name="className">The className, usually the class that is calling the method.</param>
        /// <param name="message">The message.</param>
        /// <param name="method">The path, usually denotes the class and method calling this method.</param>
        /// <param name="defaultStatusEvent">The default status event (log using the default logger).</param>
        /// <param name="code">The code(optional), denotes the code enum for a message.</param>
        private static void Log(CdmStatusLevel level, CdmCorpusContext ctx, string className, string message, string method, Action <string> defaultStatusEvent, string corpusPath, CdmLogCode code = CdmLogCode.None)
        {
            // Store a record of the event.
            // Save some dict init and string formatting cycles by checking
            // whether the recording is actually enabled.
            if (ctx.Events.IsRecording)
            {
                var theEvent = new Dictionary <string, string>
                {
                    { "timestamp", TimeUtils.GetFormattedDateString(DateTimeOffset.UtcNow) },
                    { "level", level.ToString() },
                    { "class", className },
                    { "message", message },
                    { "method", method }
                };

                if (level == CdmStatusLevel.Error || level == CdmStatusLevel.Warning)
                {
                    theEvent.Add("code", code.ToString());
                }

                if (ctx.CorrelationId != null)
                {
                    theEvent.Add("correlationId", ctx.CorrelationId);
                }

                if (corpusPath != null)
                {
                    theEvent.Add("corpuspath", corpusPath);
                }

                ctx.Events.Add(theEvent);
            }

            string formattedMessage = FormatMessage(className, message, method, ctx.CorrelationId, corpusPath);

            if (ctx.StatusEvent != null)
            {
                ctx.StatusEvent.Invoke(level, formattedMessage);
            }
            else
            {
                defaultStatusEvent(formattedMessage);
            }
        }
示例#2
0
        /// <summary>
        /// Log to the specified status level by using the status event on the corpus context (if it exists) or to the default logger.
        /// The log level, tag, message and path values are also added as part of a new entry to the log recorder.
        /// </summary>
        /// <param name="level">The status level to log to.</param>
        /// <param name="ctx">The CDM corpus context.</param>
        /// <param name="tag">The tag, usually the class that is calling the method.</param>
        /// <param name="message">The message.</param>
        /// <param name="path">The path, usually denotes the class and method calling this method.</param>
        /// <param name="defaultStatusEvent">The default status event (log using the default logger).</param>
        private static void Log(CdmStatusLevel level, CdmCorpusContext ctx, string tag, string message, string path, Action <string> defaultStatusEvent)
        {
            // Write message to the configured logger
            if (level >= ctx.ReportAtLevel)
            {
                // Store a record of the event.
                // Save some dict init and string formatting cycles by checking
                // whether the recording is actually enabled.
                if (ctx.Events.IsRecording)
                {
                    var theEvent = new Dictionary <string, string>
                    {
                        { "timestamp", TimeUtils.GetFormattedDateString(DateTimeOffset.UtcNow) },
                        { "level", level.ToString() },
                        { "tag", tag },
                        { "message", message },
                        { "path", path }
                    };

                    if (ctx.CorrelationId != null)
                    {
                        theEvent.Add("correlationId", ctx.CorrelationId);
                    }

                    ctx.Events.Add(theEvent);
                }

                string formattedMessage = FormatMessage(tag, message, path, ctx.CorrelationId);

                if (ctx.StatusEvent != null)
                {
                    ctx.StatusEvent.Invoke(level, formattedMessage);
                }
                else
                {
                    defaultStatusEvent(formattedMessage);
                }
            }
        }
示例#3
0
        /// <summary>
        /// Log to the specified status level by using the status event on the corpus context (if it exists) or to the default logger.
        /// The log level, className, message and path values are also added as part of a new entry to the log recorder.
        /// </summary>
        /// <param name="level">The status level to log to.</param>
        /// <param name="ctx">The CDM corpus context.</param>
        /// <param name="className">The className, usually the class that is calling the method.</param>
        /// <param name="message">The message.</param>
        /// <param name="method">The path, usually denotes the class and method calling this method.</param>
        /// <param name="defaultStatusEvent">The default status event (log using the default logger).</param>
        /// <param name="code">The code(optional), denotes the code enum for a message.</param>
        private static void Log(CdmStatusLevel level, CdmCorpusContext ctx, string className, string message, string method,
                                Action <string> defaultStatusEvent, string corpusPath, CdmLogCode code = CdmLogCode.None, bool ingestTelemetry = false)
        {
            if (ctx.SuppressedLogCodes.Contains(code))
            {
                return;
            }

            // Store a record of the event.
            // Save some dict init and string formatting cycles by checking
            // whether the recording is actually enabled.
            if (level >= ctx.ReportAtLevel)
            {
                string timestamp = TimeUtils.GetFormattedDateString(DateTimeOffset.UtcNow);

                // Store a record of the event.
                // Save some dict init and string formatting cycles by checking
                // whether the recording is actually enabled.
                if (ctx.Events.IsRecording)
                {
                    var theEvent = new Dictionary <string, string>
                    {
                        { "timestamp", TimeUtils.GetFormattedDateString(DateTimeOffset.UtcNow) },
                        { "level", level.ToString() },
                        { "class", className },
                        { "message", message },
                        { "method", method }
                    };

                    if (level == CdmStatusLevel.Error || level == CdmStatusLevel.Warning)
                    {
                        theEvent.Add("code", code.ToString());
                    }

                    if (ctx.CorrelationId != null)
                    {
                        theEvent.Add("cid", ctx.CorrelationId);
                    }

                    if (corpusPath != null)
                    {
                        theEvent.Add("path", corpusPath);
                    }

                    ctx.Events.Add(theEvent);
                }

                string formattedMessage = FormatMessage(className, message, method, ctx.CorrelationId, corpusPath);

                if (ctx.StatusEvent != null)
                {
                    ctx.StatusEvent.Invoke(level, formattedMessage);
                }
                else
                {
                    defaultStatusEvent(formattedMessage);
                }

                // Ingest the logs into telemetry database
                if (ctx.Corpus.TelemetryClient != null)
                {
                    ctx.Corpus.TelemetryClient.AddToIngestionQueue(timestamp, level, className, method, corpusPath, message, ingestTelemetry, code);
                }
            }
        }