/// <summary> /// Convert log message domain model to contract. /// </summary> /// <param name="source">The source object.</param> /// <returns>Log message contract object</returns> public static Contract.Data.Tracing.LogMessage ToContract(this DataAccess.Model.Tracing.LogMessage source) { return(new Contract.Data.Tracing.LogMessage { LogLevel = (Contract.Data.Tracing.LogLevel)source.LogLevel, Component = (Contract.Data.Tracing.Component)Enum.Parse(typeof(Contract.Data.Tracing.Component), source.Component), Message = source.Message, Sender = source.Sender, Timestamp = source.Timestamp }); }
/// <summary> /// Logs the message. /// </summary> /// <param name="timestamp">The timestamp.</param> /// <param name="logLevel">The log level.</param> /// <param name="component">The component.</param> /// <param name="sender">The sender.</param> /// <param name="message">The message.</param> public void LogMessage(DateTime timestamp, LogLevel logLevel, Component component, string sender, string message) { var logMessage = new LogMessage { Timestamp = timestamp, LogLevel = (int)logLevel, Component = component.ToString(), Sender = sender, Message = message }; // save the log message to the database lock (LockObject) { this.repository.Add(logMessage); this.repository.Save(); } // Also trace the message, to use this feature as well :) Trace.WriteLine(string.Format("{0} - {1} - {2}", timestamp, logLevel, message), string.Format("{0} ({1})", component, sender)); }