private void FillLogMessage(LogMessage logMessage, MethodBase methodBase, LogLevel logLevel, object message, Exception exception = null) { logMessage.Level = logLevel; logMessage.Type = methodBase.DeclaringType.Name; logMessage.Method = methodBase.Name; logMessage.Application = ConfigSettings.ApplicationName; logMessage.Message = message; logMessage.Exception = exception; }
private void CreateLogMessageAndSend(MethodBase methodBase, LogLevel logLevel, object message, Exception exception, bool asynchronously) { var logMessage = new LogMessage(); if (asynchronously) { Task.Factory.StartNew(() => { FillLogMessage(logMessage, methodBase, logLevel, message, exception); Send(logMessage); }); } else { FillLogMessage(logMessage, methodBase, logLevel, message, exception); Send(logMessage); } }
public void Send(LogMessage logMessage, string queueName = @".\private$\LogMessages") { logMessage.ThrowIfNull("logMessage"); queueName.ThrowIfNull("queueName"); try { using (var queue = new MessageQueue(string.Format(@"FormatName:Direct=OS:{0}", queueName))) { var message = new Message { Label = "LogMsmqMessage", Body = new LogMsmqMessage(BinarySerializationHelper.Serialize(logMessage)) }; queue.Send(message); } } catch (Exception ex) { Trace.WriteLine(ex); throw; } }
private void Send(LogMessage logMessage) { Trace.WriteLine(string.Format("Sending message: {0}", logMessage)); LogMessageSender.Send(logMessage, ConfigSettings.LoggingQueue); }