示例#1
0
 /// <summary>
 /// Write an exception to the log
 /// </summary>
 /// <example>
 ///     Use anonymous objects to pass properties:
 ///     log.WriteEvent("Message received", new { Category = "Blue", Level = 4 });
 /// </example>
 /// <example>
 ///     Use non-anonymous (POCO) objects to pass properties (all public properties are logged):
 ///     log.WriteEvent("Message received", new ProductInfo { Category = "Blue", Level = 4 });
 /// </example>
 /// <example>
 ///   Use dictionary to pass properties:
 ///     log.WriteEvent("Message received", new Dictionary<string, object> { {"Category", "Blue"}, {"Level", 4"} });
 /// </example>
 /// <example>
 ///   Use xml to pass properties (only logs elements under root):
 ///     log.WriteEvent("Message received", XmlDoc.LoadXml("<Root><Category>Blue</Category><Level>4</Level></Root>") );
 /// </example>
 /// <param name="log">Log to write to</param>
 /// <param name="ex">Exception to log</param>
 /// <param name="properties">See examples</param>
 /// <param name="correlationId">A value to correlate actions across calls and processes</param>
 public static Task WriteError(this ILog log, Exception ex, Telemetry.LogSeverity severity = Telemetry.LogSeverity.Error, object properties = null, string correlationId = null)
 {
     return(log.WriteTelemetry(new Telemetry {
         Type = Telemetry.TelemetryType.Error,
         Exception = ex,
         Severity = severity,
         CorrelationId = correlationId,
         Properties = properties == null ? (object)ex.Data : (properties.ToDictionary().Merge(ex.Data.ToDictionary()))
     }));
 }
示例#2
0
 /// <summary>
 /// Write a trace to the log
 /// </summary>
 /// <param name="log">Log to write to</param>
 /// <param name="message">Message to write</param>
 /// <param name="severity">Severity of trace</param>
 /// <param name="properties">See examples in WriteError</param>
 /// <param name="correlationId">A value to correlate actions across calls and processes</param>
 public static Task WriteTrace(this ILog log, string message, Telemetry.LogSeverity severity, object properties = null, string correlationId = null)
 {
     return(log.WriteTelemetry(new Telemetry {
         Type = Telemetry.TelemetryType.Trace,
         Message = message,
         Severity = severity,
         CorrelationId = correlationId,
         Properties = properties
     }));
 }