/// <summary> /// Tries to make a CustomerLogData object containing a CustomerId and another object. /// CustomerId will be taken from the Attributes of a TraceSource. /// </summary> /// <param name="source">TraceSource holding customerid in it's Attributes.</param> /// <param name="data">Object with data to add to the CustomerLogData</param> /// <param name="customerLogData">out the new CustomerLogData</param> /// <returns>true if successful, false if not</returns> public static bool TryParseFromData(TraceSource source, object data, out CustomerLogData customerLogData) { if (source != null) { if (Guid.TryParse(source.Attributes["customerid"], out Guid customerId) && (!(data is CustomerLogData))) { customerLogData = new CustomerLogData() { CustomerId = customerId, Data = data }; return(true); } } customerLogData = null; return(false); }
/// <summary> /// Tries to make a CustomerLogData object containing a CustomerId and a message. /// CustomerId will be taken from the Attributes of a TraceSource. /// </summary> /// <param name="source">TraceSource holding customerid in it's Attributes.</param> /// <param name="message">Message string to add to the CustomerLogData</param> /// <param name="customerLogData">out the new CustomerLogData</param> /// <returns>true if successful, false if not</returns> public static bool TryParseFromMessage(TraceSource source, string message, out CustomerLogData customerLogData) { if (source != null) { var sourceCustomerId = source.Attributes["customerid"]; if (Guid.TryParse(sourceCustomerId, out Guid customerId)) { customerLogData = new CustomerLogData() { CustomerId = customerId, Data = message }; return(true); } } customerLogData = null; return(false); }
/// <summary> /// Writes an object to the log with the specified severity and a specific customerID. /// </summary> /// <param name="log">The log to write to.</param> /// <param name="logLevel">The severity of the message.</param> /// <param name="objectToSend">The data to log.</param> /// <param name="customerID">The specific customerID to send with the log.</param> public static void Write <T>(this ILog log, LogLevel logLevel, T objectToSend, Guid customerID) { CustomerLogData data = new CustomerLogData(objectToSend, customerID); log.Write(logLevel, data); }
/// <summary> /// Writes a message to the log with the specified severity and a specific customerID. /// </summary> /// <param name="log">The log to write to.</param> /// <param name="logLevel">The severity of the message.</param> /// <param name="message">The text of the message to log.</param> /// <param name="customerID">The specific customerID to send with the log.</param> public static void Write(this ILog log, LogLevel logLevel, string message, Guid customerID) { CustomerLogData data = new CustomerLogData(message, customerID); log.Write(logLevel, data); }