Ejemplo n.º 1
0
        public void WriteLogWithTwoLogWriters()
        {
            Mock<IConfigManager> configManager = GetMockConfigManager("LoggingUnitTests", "Debug");

            NLogLogWriter logWriter = new NLogLogWriter(configManager.Object);

            LogRecord r =
                new LogRecord(LogSeverityType.Error, "WriteLogWithTwoLogWriters", "Message text")
                {
                    AdditionalInfo1 = "AddlInfo1",
                    AdditionalInfo2 = "AddlInfo2",
                    AlertCondition = "Condition",
                    ReferenceId = "RefID123"
                };

            logWriter.WriteLog(r);

            NLogLogWriter logWriter2 = new NLogLogWriter(configManager.Object, "UnitTest2");

            r.ReferenceId = "RefID345";

            logWriter.WriteLog(r);

            logWriter.Flush();
        }
Ejemplo n.º 2
0
        private static void WriteThread()
        {
            Mock<IConfigManager> configManager = GetMockConfigManager("LoggingUnitTests", "Debug");

            NLogLogWriter logWriter = new NLogLogWriter(configManager.Object, "WriteThread");

            string threadId = Thread.CurrentThread.ManagedThreadId.ToString();
            string title = "WriteLogWithMultipleThreads (" + threadId + ")";

            for (int x = 0; x < 150; x++)
            {
                LogRecord r =
                    new LogRecord(LogSeverityType.Error, title + ":" + x.ToString(), "Message text")
                    {
                        AdditionalInfo1 = "AddlInfo1",
                        AdditionalInfo2 = "AddlInfo2",
                        AlertCondition = "Condition",
                        ReferenceId = "RefID123"
                    };

                logWriter.WriteLog(r);
            }
        }
Ejemplo n.º 3
0
        private void WriteLogBase(LogRecord record, string messageType, params object[] args)
        {
            TraceManager.TraceEvent(TraceEventType.Verbose, TraceEvent.BeginWriteLog, "Starting log write request... App Name: {0}", _applicationName);

            string logEnabled = null;
            if (TraceManager.ShouldTrace(TraceEventType.Verbose))
            {
                logEnabled = IsSeverityEnabledForLogging(record.Severity) ? "Yes" : "No";
            }

            TraceManager.TraceEvent(
                TraceEventType.Verbose, TraceEvent.WriteLog, "Proposed log: App Name: {0}; WillBeLogged: {1}; LogRecord = {2}", _applicationName, logEnabled, record.ToString());
            WriteLogInternal(record, messageType, args);

            TraceManager.TraceEvent(TraceEventType.Verbose, TraceEvent.EndWriteLog, "Ended log write request. App Name: {0}", _applicationName);
        }
Ejemplo n.º 4
0
 protected abstract void WriteLogInternal(LogRecord record, string messageType, params object[] args);
Ejemplo n.º 5
0
        public void WriteLog(LogRecord record)
        {
            if (record == null)
            {
                throw new ArgumentNullException("record");
            }

            WriteLogBase(record, "T");
        }
Ejemplo n.º 6
0
        private void WriteLogInternal(LogRecord record, string messageType, params object[] args)
        {
            System.Console.Write(record.Severity.ToString() + ": " + record.Message);

            if (record.Exception != null)
            {
                System.Console.WriteLine("; Exception: " + record.Exception.Message);
            }
            else
            {
                System.Console.WriteLine();
            }
        }
Ejemplo n.º 7
0
 public void WriteLog(LogRecord record)
 {
     WriteLogInternal(record, "T");
 }