コード例 #1
0
ファイル: Logger.cs プロジェクト: mrvshah/Logging
 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;
 }
コード例 #2
0
ファイル: Logger.cs プロジェクト: mrvshah/Logging
        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);
            }
        }
コード例 #3
0
        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;
            }
        }
コード例 #4
0
ファイル: Logger.cs プロジェクト: mrvshah/Logging
 private void Send(LogMessage logMessage)
 {
     Trace.WriteLine(string.Format("Sending message: {0}", logMessage));
     LogMessageSender.Send(logMessage, ConfigSettings.LoggingQueue);
 }