public void TestPathThatDoesNotEndInSlash() { var corpus = new CdmCorpusDefinition(); var callback = new EventCallback(); var functionWasCalled = false; CdmStatusLevel functionParameter1 = CdmStatusLevel.Info; string functionParameter2 = null; callback.Invoke = (CdmStatusLevel statusLevel, string message1) => { functionWasCalled = true; functionParameter1 = statusLevel; functionParameter2 = message1; }; corpus.SetEventCallback(callback); var absolutePath = corpus.Storage.CreateAbsoluteCorpusPath("Abc", new CdmManifestDefinition(null, null) { Namespace = "cdm", FolderPath = "Mnp" }); Assert.AreEqual("cdm:Mnp/Abc", absolutePath); Assert.AreEqual(functionWasCalled, true); Assert.AreEqual(functionParameter1, CdmStatusLevel.Warning); Assert.IsTrue(functionParameter2.Contains("Expected path prefix to end in /, but it didn't. Appended the /")); }
public ResolveContext(CdmCorpusDefinition corpus, EventCallback statusEvent, CdmStatusLevel?reportAtLevel = null) { this.ReportAtLevel = reportAtLevel != null ? reportAtLevel.Value : CdmStatusLevel.Info; this.StatusEvent = statusEvent; this.Cache = new ConcurrentDictionary <string, object>(); this.Corpus = corpus; }
/// <summary> /// Log cdm messages /// </summary> /// <param name="logger"></param> /// <param name="level"></param> /// <param name="msg"></param> private void LogCdm(ILogger logger, CdmStatusLevel level, string msg) { switch (level) { case CdmStatusLevel.Error: logger.Error("{msg}", msg); break; case CdmStatusLevel.Warning: logger.Warning("{msg}", msg); break; case CdmStatusLevel.Progress: logger.Verbose("{msg}", msg); break; case CdmStatusLevel.Info: if (msg.StartsWith("CdmCorpusDefinition")) { logger.Verbose("{msg}", msg); } else { logger.Information("{msg}", msg); } break; } }
/// <summary> /// Enqueue the request queue with the information to be logged /// </summary> /// <param name="timestamp">The log timestamp</param> /// <param name="level">Logging status level</param> /// <param name="className">Usually the class that is calling the method</param> /// <param name="method">Usually denotes method calling this method</param> /// <param name="corpusPath">Usually denotes corpus path of document</param> /// <param name="message">Informational message</param> /// <param name="requireIngestion">(Optional) Whether the log needs to be ingested</param> /// <param name="code">(Optional) Error or warning code</param> public void AddToIngestionQueue(string timestamp, CdmStatusLevel level, string className, string method, string corpusPath, string message, bool requireIngestion = false, CdmLogCode code = CdmLogCode.None) { // Check if the Kusto config and the concurrent queue has been initialized if (this.config == null || this.requestQueue == null) { return; } // Not ingest logs from telemetry client to avoid cycling if (className == nameof(TelemetryKustoClient)) { return; } // If ingestion is not required and the level is Progress if (level == CdmStatusLevel.Progress && !requireIngestion) { // If the execution time needs to be logged if (logExecTimeMethods.Contains(method)) { // Check if the log contains execution time info string execTimeMessage = "Leaving scope. Time elapsed:"; // Skip if the log is not for execution time if (!message.StartsWith(execTimeMessage)) { return; } } // Skip if the method execution time doesn't need to be logged else { return; } } // Configured in case no user-created content can be ingested into Kusto due to compliance issue // Note: The RemoveUserContent property could be deleted in the if the compliance issue gets resolved if (this.config.RemoveUserContent) { corpusPath = null; if (level == CdmStatusLevel.Warning || level == CdmStatusLevel.Error) { message = null; } } string logEntry = ProcessLogEntry(timestamp, className, method, message, code, corpusPath, this.ctx.CorrelationId, this.ctx.Events.ApiCorrelationId, this.ctx.Corpus.AppId); // Add the status level and log entry to the queue to be ingested this.requestQueue.Enqueue(new Tuple <CdmStatusLevel, string>(level, logEntry)); }
private static void Log(CdmStatusLevel level, CdmCorpusContext ctx, string message, Action <string> defaultStatusEvent) { if (level >= ctx.ReportAtLevel) { if (ctx != null && ctx.StatusEvent != null) { ctx.StatusEvent.Invoke(level, message); } else { defaultStatusEvent(message); } } }
private static void Log(CdmStatusLevel level, CdmCorpusContext ctx, string tag, string message, string path, Action <string> defaultStatusEvent) { if (level >= ctx.ReportAtLevel) { string formattedMessage = FormatMessage(tag, message, path); if (ctx != null && ctx.StatusEvent != null) { ctx.StatusEvent.Invoke(level, formattedMessage); } else { defaultStatusEvent(formattedMessage); } } }
/// <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); } }
/// <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); } } }
/// <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); } } }