Logger

Namespace: Nuke.Common
We found 10 examples in language CSharp for this search. You will see 47 fragments of code.

		[Test]
		public void Closed ()
		{
			_form = new Form ();
			EventLogger logger = new EventLogger (_form);
			_form.ShowInTaskbar = false;
			_form.Show ();
			Application.DoEvents ();
			Assert.AreEqual (0, logger.CountEvents ("Closed"), "#1");
			_form.Close ();
			Application.DoEvents ();
			Assert.AreEqual (1, logger.CountEvents ("Closed"), "#2");
			_form.Close ();
			Application.DoEvents ();
			Assert.AreEqual (1, logger.CountEvents ("Closed"), "#3");
		}

		[Test]
		public void Closed_Dialog ()
		{
			_form = new DelayedCloseForm ();
			EventLogger logger = new EventLogger (_form);
			_form.ShowInTaskbar = false;
			_form.ShowDialog ();
			Assert.AreEqual (1, logger.CountEvents ("Closed"), "#1");
			_form.ShowDialog ();
			Assert.AreEqual (2, logger.CountEvents ("Closed"), "#2");
			_form.Close ();
			Application.DoEvents ();
			Assert.AreEqual (2, logger.CountEvents ("Closed"), "#3");
		}

		[Test]
		public void Closing ()
		{
			_form = new Form ();
			EventLogger logger = new EventLogger (_form);
			_form.ShowInTaskbar = false;
			_form.Show ();
			Application.DoEvents ();
			Assert.AreEqual (0, logger.CountEvents ("Closing"), "#1");
			_form.Close ();
			Application.DoEvents ();
			Assert.AreEqual (1, logger.CountEvents ("Closing"), "#2");
		}

		[Test]
		public void Closing_Dialog ()
		{
			_form = new DelayedCloseForm ();
			EventLogger logger = new EventLogger (_form);
			_form.ShowInTaskbar = false;
			_form.ShowDialog ();
			Assert.AreEqual (1, logger.CountEvents ("Closing"), "#1");
			_form.ShowDialog ();
			Assert.AreEqual (2, logger.CountEvents ("Closing"), "#2");
			_form.Close ();
			Application.DoEvents ();
			Assert.AreEqual (2, logger.CountEvents ("Closing"), "#3");
		}

		[Test]
		public void FormClosing_Dialog ()
		{
			_form = new DelayedCloseForm ();
			EventLogger logger = new EventLogger (_form);
			_form.ShowInTaskbar = false;
			Assert.AreEqual (0, logger.CountEvents ("FormClosing"));
			_form.ShowDialog ();
			Assert.AreEqual (1, logger.CountEvents ("FormClosing"));
			_form.ShowDialog ();
			Assert.AreEqual (2, logger.CountEvents ("FormClosing"));
		}

		[Test]
		public void Load_Dialog ()
		{
			_form = new DelayedCloseForm ();
			EventLogger logger = new EventLogger (_form);
			_form.ShowInTaskbar = false;
			Assert.AreEqual (0, logger.CountEvents ("Load"), "#1");
			_form.ShowDialog ();
			Assert.AreEqual (1, logger.CountEvents ("Load"), "#2");
			_form.ShowDialog ();
			Assert.AreEqual (2, logger.CountEvents ("Load"), "#3");
		}


		void CheckLoggedMessagesInOrder (TestMessageLogger logger, string [] values, string prefix)
		{
			try {
				for (int i = 0; i < values.Length; i++) {
					logger.CheckLoggedMessageHead (values [i], prefix + "#" + i);
				}
				if (logger.NormalMessageCount > 0)
					Assert.Fail ("{0}: Expected {1} messages, but found {2}",
						prefix, values.Length, values.Length + logger.NormalMessageCount);
			} catch (NUnit.Framework.AssertionException) {
				logger.DumpMessages ();
				throw;
			}
		}

		void CheckMessage (TestMessageLogger logger, string culture, string items, string id)
		{
			logger.CheckLoggedMessageHead (String.Format ("Culture: {0} -- ResXFile: {1}", culture, items), id);
		}

		void CheckMessage2 (TestMessageLogger logger, string culture, string resx_files, string nonresx_files, string id)
		{
			logger.CheckLoggedMessageHead (String.Format ("Culture: {0} -- ResXFiles: {1} NonResXFiles: {2}", culture, resx_files, nonresx_files), id);
		}

		void CheckLoggedMessageAny (TestMessageLogger logger, string expected, string id)
		{
			if (logger.CheckAny (expected, MessageImportance.Normal) == 1)
				Assert.Fail ("{0}: Expected message '{1}' was not emitted.", id, expected);
		}

        Logger CreateLogger();
            public Logger CreateLogger()
            {
                return GetCurrentLogger();
            }

            public Logger CreateLogger()
            {
                return LogManager.GetLogger(_loggerName);
            }

            public Logger CreateLogger()
            {
                return LogManager.GetCurrentClassLogger(_type);
            }


        /// <summary>
        /// Set the parent for logger object
        /// </summary>
        /// <param name="logger">logger whose parent is to be set</param>
        /// <param name="parent">parent logger</param>
        private static void DoSetParent(Logger logger, Logger parent)
        {
            logger.SetParent(parent);
        }

        /// <summary>
        /// Get the looger by name
        /// </summary>
        /// <param name="name">name of the logger</param>
        /// <returns>Logger Object</returns>
        public Logger GetLogger(string name)
        {
            if (loggers.ContainsKey(name))
                return loggers[name];
            else
                return null;
        }

        /// <summary>
        /// Get an enumeration of known logger names.
        /// </summary>
        /// <returns>enumeration of logger name strings</returns>
        [MethodImpl(MethodImplOptions.Synchronized)]
        public Dictionary<String, Logger> GetLoggerNames()
        {
            return loggers;
        }

#if NETFULL
using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;

namespace Utilities.Logging
{
    public static class Log
    {
        private static IEnumerable<ILogger> _loggers;
        private static readonly Object _lock = new Object();


        public static void Write(String message)
        {
            Initialize();

            SimpleLoggerEntry entry = new SimpleLoggerEntry(message);

            lock (_lock)
            {
                foreach (ILogger logger in _loggers)
                {
                    logger.Write(entry);
                }
            }
        }

        public static void Write(Exception ex)
        {
            Initialize();

            ExceptionLoggerEntry entry = new ExceptionLoggerEntry(ex);

            lock (_lock)
            {
                foreach (ILogger logger in _loggers)
                {
                    logger.Write(entry);
                }
            }
        }

        public static void Write(ILoggerEntry entry)
        {
            Initialize();

            lock (_lock)
            {
                foreach (ILogger logger in _loggers)
                {
                    logger.Write(entry);
                }
            }
        }


        public static void WriteToFile(String message)
        {
            Initialize();

            SimpleLoggerEntry entry = new SimpleLoggerEntry(message);

            lock (_lock)
            {
                foreach (ILogger logger in _loggers)
                {
                    if (logger is FileLogger)
                    {
                        logger.Write(entry);
                    }
                }
            }
        }

        public static void WriteToFile(Exception ex)
        {
            Initialize();

            ExceptionLoggerEntry entry = new ExceptionLoggerEntry(ex);

            lock (_lock)
            {
                foreach (ILogger logger in _loggers)
                {
                    if (logger is FileLogger)
                    {
                        logger.Write(entry);
                    }
                }
            }
        }

        public static void WriteToFile(ILoggerEntry entry)
        {
            Initialize();

            lock (_lock)
            {
                foreach (ILogger logger in _loggers)
                {
                    if (logger is FileLogger)
                    {
                        logger.Write(entry);
                    }
                }
            }
        }


        public static void WriteToEventLog(String message)
        {
            Initialize();

            SimpleLoggerEntry entry = new SimpleLoggerEntry(message);

            lock (_lock)
            {
                foreach (ILogger logger in _loggers)
                {
                    if (logger is EventLogLogger)
                    {
                        logger.Write(entry);
                    }
                }
            }
        }

        public static void WriteToEventLog(Exception ex)
        {
            Initialize();

            ExceptionLoggerEntry entry = new ExceptionLoggerEntry(ex);

            lock (_lock)
            {
                foreach (ILogger logger in _loggers)
                {
                    if (logger is EventLogLogger)
                    {
                        logger.Write(entry);
                    }
                }
            }
        }

        public static void WriteToEventLog(ILoggerEntry entry)
        {
            Initialize();

            lock (_lock)
            {
                foreach (ILogger logger in _loggers)
                {
                    if (logger is EventLogLogger)
                    {
                        logger.Write(entry);
                    }
                }
            }
        }


        public static void WriteToMail(String message)
        {
            Initialize();

            SimpleLoggerEntry entry = new SimpleLoggerEntry(message);

            lock (_lock)
            {
                foreach (ILogger logger in _loggers)
                {
                    if (logger is MailLogger)
                    {
                        logger.Write(entry);
                    }
                }
            }
        }

        public static void WriteToMail(Exception ex)
        {
            Initialize();

            ExceptionLoggerEntry entry = new ExceptionLoggerEntry(ex);

            lock (_lock)
            {
                foreach (ILogger logger in _loggers)
                {
                    if (logger is MailLogger)
                    {
                        logger.Write(entry);
                    }
                }
            }
        }

        public static void WriteToMail(ILoggerEntry entry)
        {
            Initialize();

            lock (_lock)
            {
                foreach (ILogger logger in _loggers)
                {
                    if (logger is MailLogger)
                    {
                        logger.Write(entry);
                    }
                }
            }
        }


        public static void WriteToConsole(String message)
        {
            Initialize();

            SimpleLoggerEntry entry = new SimpleLoggerEntry(message);

            lock (_lock)
            {
                foreach (ILogger logger in _loggers)
                {
                    if (logger is ConsoleLogger)
                    {
                        logger.Write(entry);
                    }
                }
            }
        }

        public static void WriteToConsole(Exception ex)
        {
            Initialize();

            ExceptionLoggerEntry entry = new ExceptionLoggerEntry(ex);

            lock (_lock)
            {
                foreach (ILogger logger in _loggers)
                {
                    if (logger is ConsoleLogger)
                    {
                        logger.Write(entry);
                    }
                }
            }
        }

        public static void WriteToConsole(ILoggerEntry entry)
        {
            Initialize();

            lock (_lock)
            {
                foreach (ILogger logger in _loggers)
                {
                    if (logger is ConsoleLogger)
                    {
                        logger.Write(entry);
                    }
                }
            }
        }


        private static void Initialize()
        {
            _loggers = ConfigurationManager.GetSection("utilities/logging") as IEnumerable<ILogger>;

            if (_loggers == null)
            {
                throw new ArgumentNullException("utilities/logging", "Section is not exists!");
            }
        }
    }
}
#endif

        [Fact]
        public void BasicTests()
        {
            var logger = new MockLogger();

            logger.Reset();
            NoNamespace.CouldNotOpenSocket(logger, "microsoft.com");
            Assert.Equal(LogLevel.Critical, logger.LastLogLevel);
            Assert.Null(logger.LastException);
            Assert.Equal("Could not open socket to `microsoft.com`", logger.LastFormattedString);
            Assert.Equal(1, logger.CallCount);

            logger.Reset();
            Level1.OneLevelNamespace.CouldNotOpenSocket(logger, "microsoft.com");
            Assert.Equal(LogLevel.Critical, logger.LastLogLevel);
            Assert.Null(logger.LastException);
            Assert.Equal("Could not open socket to `microsoft.com`", logger.LastFormattedString);
            Assert.Equal(1, logger.CallCount);

            logger.Reset();
            Level1.Level2.TwoLevelNamespace.CouldNotOpenSocket(logger, "microsoft.com");
            Assert.Equal(LogLevel.Critical, logger.LastLogLevel);
            Assert.Null(logger.LastException);
            Assert.Equal("Could not open socket to `microsoft.com`", logger.LastFormattedString);
            Assert.Equal(1, logger.CallCount);
        }

        [Fact]
        public void EnableTest()
        {
            var logger = new MockLogger();

            logger.Reset();
            logger.Enabled = false;
            NoNamespace.CouldNotOpenSocket(logger, "microsoft.com");
            Assert.Equal(0, logger.CallCount);          // ensure the logger doesn't get called when it is disabled
        }

        [Fact]
        public void ArgTest()
        {
            var logger = new MockLogger();

            logger.Reset();
            ArgTestExtensions.Method1(logger);
            Assert.Null(logger.LastException);
            Assert.Equal("M1", logger.LastFormattedString);
            Assert.Equal(1, logger.CallCount);

            logger.Reset();
            ArgTestExtensions.Method2(logger, "arg1");
            Assert.Null(logger.LastException);
            Assert.Equal("M2 arg1", logger.LastFormattedString);
            Assert.Equal(1, logger.CallCount);

            logger.Reset();
            ArgTestExtensions.Method3(logger, "arg1", 2);
            Assert.Null(logger.LastException);
            Assert.Equal("M3 arg1 2", logger.LastFormattedString);
            Assert.Equal(1, logger.CallCount);

            logger.Reset();
            ArgTestExtensions.Method4(logger, new InvalidOperationException("A"));
            Assert.Equal("A", logger.LastException!.Message);
            Assert.Equal("M4", logger.LastFormattedString);
            Assert.Equal(1, logger.CallCount);

            logger.Reset();
            ArgTestExtensions.Method5(logger, new InvalidOperationException("A"), new InvalidOperationException("B"));
            Assert.Equal("A", logger.LastException!.Message);
            Assert.Equal("M5 System.InvalidOperationException: B", logger.LastFormattedString);
            Assert.Equal(1, logger.CallCount);

            logger.Reset();
            ArgTestExtensions.Method6(logger, new InvalidOperationException("A"), 2);
            Assert.Equal("A", logger.LastException!.Message);
            Assert.Equal("M6 2", logger.LastFormattedString);
            Assert.Equal(1, logger.CallCount);

            logger.Reset();
            ArgTestExtensions.Method7(logger, 1, new InvalidOperationException("B"));
            Assert.Equal("B", logger.LastException!.Message);
            Assert.Equal("M7 1", logger.LastFormattedString);
            Assert.Equal(1, logger.CallCount);

            logger.Reset();
            ArgTestExtensions.Method8(logger, 1, 2, 3, 4, 5, 6, 7);
            Assert.Equal("M81234567", logger.LastFormattedString);
            Assert.Equal(1, logger.CallCount);

            logger.Reset();
            ArgTestExtensions.Method9(logger, 1, 2, 3, 4, 5, 6, 7);
            Assert.Equal("M9 1 2 3 4 5 6 7", logger.LastFormattedString);
            Assert.Equal(1, logger.CallCount);

            logger.Reset();
            ArgTestExtensions.Method10(logger, 1);
            Assert.Equal("M101", logger.LastFormattedString);
            Assert.Equal(1, logger.CallCount);
        }

        [Fact]
        public void CollectionTest()
        {
            var logger = new MockLogger();

            logger.Reset();
            CollectionTestExtensions.M0(logger);
            TestCollection(1, logger);

            logger.Reset();
            CollectionTestExtensions.M1(logger, 0);
            TestCollection(2, logger);

            logger.Reset();
            CollectionTestExtensions.M2(logger, 0, 1);
            TestCollection(3, logger);

            logger.Reset();
            CollectionTestExtensions.M3(logger, 0, 1, 2);
            TestCollection(4, logger);

            logger.Reset();
            CollectionTestExtensions.M4(logger, 0, 1, 2, 3);
            TestCollection(5, logger);

            logger.Reset();
            CollectionTestExtensions.M5(logger, 0, 1, 2, 3, 4);
            TestCollection(6, logger);

            logger.Reset();
            CollectionTestExtensions.M6(logger, 0, 1, 2, 3, 4, 5);
            TestCollection(7, logger);

            logger.Reset();
            CollectionTestExtensions.M7(logger, 0, 1, 2, 3, 4, 5, 6);
            TestCollection(8, logger);

            logger.Reset();
            CollectionTestExtensions.M8(logger, 0, 1, 2, 3, 4, 5, 6, 7);
            TestCollection(9, logger);

            logger.Reset();
            CollectionTestExtensions.M9(logger, LogLevel.Critical, 0, new ArgumentException("Foo"), 1);
            TestCollection(3, logger);

            Assert.True(true);
        }

        [Fact]
        public void MessageTests()
        {
            var logger = new MockLogger();

            logger.Reset();
            MessageTestExtensions.M0(logger);
            Assert.Null(logger.LastException);
            Assert.Equal(string.Empty, logger.LastFormattedString);
            Assert.Equal(LogLevel.Trace, logger.LastLogLevel);
            Assert.Equal(1, logger.CallCount);

            logger.Reset();
            MessageTestExtensions.M1(logger);
            Assert.Null(logger.LastException);
            Assert.Equal(string.Empty, logger.LastFormattedString);
            Assert.Equal(LogLevel.Debug, logger.LastLogLevel);
            Assert.Equal(1, logger.CallCount);

            logger.Reset();
            MessageTestExtensions.M5(logger, LogLevel.Trace);
            Assert.Null(logger.LastException);
            Assert.Equal(string.Empty, logger.LastFormattedString);
            Assert.Equal(LogLevel.Trace, logger.LastLogLevel);
            Assert.Equal(-1, logger.LastEventId.Id);
            Assert.Equal(1, logger.CallCount);

            logger.Reset();
            MessageTestExtensions.M6(logger, LogLevel.Trace);
            Assert.Null(logger.LastException);
            Assert.Equal(string.Empty, logger.LastFormattedString);
            Assert.Equal(LogLevel.Trace, logger.LastLogLevel);
            Assert.Equal(6, logger.LastEventId.Id);
            Assert.Equal(1, logger.CallCount);

            logger.Reset();
            MessageTestExtensions.M7(logger, LogLevel.Trace, "p", "q");
            Assert.Null(logger.LastException);
            Assert.Equal("\"p\" -> \"q\"", logger.LastFormattedString);
            Assert.Equal(LogLevel.Trace, logger.LastLogLevel);
            Assert.Equal(7, logger.LastEventId.Id);
            Assert.Equal(1, logger.CallCount);
        }

        [Fact]
        [ActiveIssue("https://github.com/dotnet/roslyn/issues/52527")]
        public void MessageTests_SuppressWarning_WarnAsError_NoError()
        {
            // Diagnostics produced by source generators do not respect the /warnAsError or /noWarn compiler flags.
            // These are handled fine by the logger generator and generate warnings. Unfortunately, the warning suppression is
            // not being observed by the C# compiler at the moment, so having these here causes build warnings.
#if false
            var logger = new MockLogger();

            logger.Reset();
            MessageTestExtensions.M2(logger, "Foo", "Bar");
            Assert.Null(logger.LastException);
            Assert.Equal(string.Empty, logger.LastFormattedString);
            AssertLastState(logger,
                new KeyValuePair<string, object?>("p1", "Foo"),
                new KeyValuePair<string, object?>("p2", "Bar"),
                new KeyValuePair<string, object?>("{OriginalFormat}", string.Empty));
            Assert.Equal(LogLevel.Trace, logger.LastLogLevel);
            Assert.Equal(1, logger.CallCount);

            logger.Reset();
            MessageTestExtensions.M3(logger, "Foo", 42);
            Assert.Null(logger.LastException);
            Assert.Equal(string.Empty, logger.LastFormattedString);
            AssertLastState(logger,
                new KeyValuePair<string, object?>("p1", "Foo"),
                new KeyValuePair<string, object?>("p2", 42),
                new KeyValuePair<string, object?>("{OriginalFormat}", string.Empty));
            Assert.Equal(LogLevel.Debug, logger.LastLogLevel);
            Assert.Equal(1, logger.CallCount);
#endif
        }

        [Fact]
        public void GetLoggerWithServices_ReturnsCompositeExceptionLoggerWithServicesLoggers()
        {
            // Arrange
            IExceptionLogger expectedLogger = CreateDummyLogger();

            using (ServicesContainer services = CreateServices(expectedLogger))
            {
                // Act
                IExceptionLogger logger = ExceptionServices.GetLogger(services);

                // Assert
                Assert.IsType<CompositeExceptionLogger>(logger);
                IEnumerable<IExceptionLogger> loggers = ((CompositeExceptionLogger)logger).Loggers;
                Assert.Equal(1, loggers.Count());
                Assert.Same(expectedLogger, loggers.Single());
            }
        }

        [Fact]
        public void GetLoggerWithServices_ReturnsSameInstance()
        {
            // Arrange
            IExceptionLogger innerLogger = CreateDummyLogger();

            using (ServicesContainer services = CreateServices(innerLogger))
            {
                IExceptionLogger firstLogger = ExceptionServices.GetLogger(services);

                // Act
                IExceptionLogger secondLogger = ExceptionServices.GetLogger(services);

                // Assert
                Assert.Same(firstLogger, secondLogger);
            }
        }

        [Fact]
        public void GetLoggerWithServices_IfServicesIsNull_Throws()
        {
            // Arrange
            ServicesContainer services = null;

            // Act & Assert
            Assert.ThrowsArgumentNull(() => ExceptionServices.GetLogger(services), "services");
        }

        [Fact]
        public void GetLoggerWithConfiguration_ReturnsCompositeExceptionLoggerWithServicesLoggers()
        {
            // Arrange
            IExceptionLogger expectedLogger = CreateDummyLogger();

            using (HttpConfiguration configuration = CreateConfiguration(expectedLogger))
            {
                // Act
                IExceptionLogger logger = ExceptionServices.GetLogger(configuration);

                // Assert
                Assert.IsType<CompositeExceptionLogger>(logger);
                IEnumerable<IExceptionLogger> loggers = ((CompositeExceptionLogger)logger).Loggers;
                Assert.Equal(1, loggers.Count());
                Assert.Same(expectedLogger, loggers.Single());
            }
        }

        [Fact]
        public void GetLoggerWithConfiguration_IfConfigurationIsNull_Throws()
        {
            // Arrange
            HttpConfiguration configuration = null;

            // Act & Assert
            Assert.ThrowsArgumentNull(() => ExceptionServices.GetLogger(configuration), "configuration");
        }

        [Fact]
        public void GetHandlerWithServices_ReturnsLastChanceHandlerWithServicesInnerHandler()
        {
            // Arrange
            IExceptionHandler expectedHandler = CreateDummyHandler();

            using (ServicesContainer services = CreateServices(expectedHandler))
            {
                // Act
                IExceptionHandler handler = ExceptionServices.GetHandler(services);

                // Assert
                Assert.IsType<LastChanceExceptionHandler>(handler);
                IExceptionHandler innerHandler = ((LastChanceExceptionHandler)handler).InnerHandler;
                Assert.Same(expectedHandler, innerHandler);
            }
        }


	public static PerfTimerLogger Get(string message)
	{
		if (PerfTimerLogger._instances == null || !PerfTimerLogger._instances.ContainsKey(message))
		{
			return null;
		}
		return PerfTimerLogger._instances[message];
	}

	public void Pause()
	{
		this._timer.Stop();
	}

	public void Unpause()
	{
		this._timer.Start();
	}

	public void Stop()
	{
		this.Dispose();
	}

	public void Dispose()
	{
		this._timer.Stop();
		long elapsedMilliseconds = this._timer.ElapsedMilliseconds;
		long elapsedTicks = this._timer.ElapsedTicks;
		PerfTimerLogger.LogResultType logResultType = this._logResultType;
		string text;
		if (logResultType != PerfTimerLogger.LogResultType.Ticks)
		{
			text = string.Format("{0} - Elapsed Milliseconds: {1}", this._message, elapsedMilliseconds);
		}
		else
		{
			text = string.Format("{0} - Elapsed Ticks: {1}", this._message, elapsedTicks);
		}
		if (this._logAction != null)
		{
			this._logAction(text);
		}
		else
		{
			UnityEngine.Debug.Log(text);
		}
		if (PerfTimerLogger._instances != null && PerfTimerLogger._instances.ContainsKey(this._message))
		{
			PerfTimerLogger._instances.Remove(this._message);
		}
	}


        public static AggregateLogger Create(params ILogger[] loggers)
        {
            var set = new HashSet<ILogger>();

            // flatten loggers
            foreach (var logger in loggers.WhereNotNull())
            {
                if (logger is AggregateLogger aggregateLogger)
                {
                    set.UnionWith(aggregateLogger._loggers);
                    continue;
                }

                set.Add(logger);
            }

            return new AggregateLogger(set.ToImmutableArray());
        }

        public static ILogger AddOrReplace(ILogger newLogger, ILogger oldLogger, Func<ILogger, bool> predicate)
        {
            if (newLogger == null)
            {
                return oldLogger;
            }

            if (oldLogger == null)
            {
                return newLogger;
            }

            var aggregateLogger = oldLogger as AggregateLogger;
            if (aggregateLogger == null)
            {
                // replace old logger with new logger
                if (predicate(oldLogger))
                {
                    // this might not aggregate logger
                    return newLogger;
                }

                // merge two
                return new AggregateLogger(ImmutableArray.Create(newLogger, oldLogger));
            }

            var set = new HashSet<ILogger>();
            foreach (var logger in aggregateLogger._loggers)
            {
                // replace this logger with new logger
                if (predicate(logger))
                {
                    set.Add(newLogger);
                    continue;
                }

                // add old one back
                set.Add(logger);
            }

            // add new logger. if we already added one, this will be ignored.
            set.Add(newLogger);
            return new AggregateLogger(set.ToImmutableArray());
        }

        public static ILogger Remove(ILogger logger, Func<ILogger, bool> predicate)
        {
            var aggregateLogger = logger as AggregateLogger;
            if (aggregateLogger == null)
            {
                // remove the logger
                if (predicate(logger))
                {
                    return null;
                }

                return logger;
            }

            // filter out loggers
            var set = aggregateLogger._loggers.Where(l => !predicate(l)).ToSet();
            if (set.Count == 1)
            {
                return set.Single();
            }

            return new AggregateLogger(set.ToImmutableArray());
        }

        public bool IsEnabled(FunctionId functionId)
        {
            return true;
        }

        public void Log(FunctionId functionId, LogMessage logMessage)
        {
            for (var i = 0; i < _loggers.Length; i++)
            {
                var logger = _loggers[i];
                if (!logger.IsEnabled(functionId))
                {
                    continue;
                }

                logger.Log(functionId, logMessage);
            }
        }

        public void LogBlockStart(FunctionId functionId, LogMessage logMessage, int uniquePairId, CancellationToken cancellationToken)
        {
            for (var i = 0; i < _loggers.Length; i++)
            {
                var logger = _loggers[i];
                if (!logger.IsEnabled(functionId))
                {
                    continue;
                }

                logger.LogBlockStart(functionId, logMessage, uniquePairId, cancellationToken);
            }
        }

		
		public void ParseArguments (string[] args)
		{
			bool autoResponse = true;
			flatArguments = new ArrayList ();
			remainingArguments = new ArrayList ();
			responseFiles = new Hashtable ();
			FileLoggerParameters = new string[10];
			foreach (string s in args) {
				if (s.StartsWith ("/noautoresponse") || s.StartsWith ("/noautorsp")) {
					autoResponse = false;
					continue;
				}
				if (s [0] != '@') {
					flatArguments.Add (s);
					continue;
				}
				string responseFilename = Path.GetFullPath (UnquoteIfNeeded (s.Substring (1)));
				if (responseFiles.ContainsKey (responseFilename))
					ReportError (1, String.Format ("We already have {0} file.", responseFilename));
				responseFiles [responseFilename] = responseFilename;
				LoadResponseFile (responseFilename);
			}
			if (autoResponse == true) {
				// FIXME: we do not allow nested auto response file
				LoadResponseFile (responseFile);
			}
			foreach (string s in flatArguments) {
				if (s [0] != '/' || !ParseFlatArgument (s))
					remainingArguments.Add (s);
			}
			if (remainingArguments.Count == 0) {
				string[] sln_files = Directory.GetFiles (Directory.GetCurrentDirectory (), "*.sln");
				string[] proj_files = Directory.GetFiles (Directory.GetCurrentDirectory (), "*proj");

				if (sln_files.Length == 0 && proj_files.Length == 0)
					ReportError (3, "Please specify the project or solution file " +
							"to build, as none was found in the current directory.");

				if (sln_files.Length == 1 && proj_files.Length > 0) {
					var projects_table = new Dictionary<string, string> ();
					foreach (string pfile in SolutionParser.GetAllProjectFileNames (sln_files [0])) {
						string full_path = Path.GetFullPath (pfile);
						projects_table [full_path] = full_path;
					}

					if (!proj_files.Any (p => !projects_table.ContainsKey (Path.GetFullPath (p))))
						// if all the project files in the cur dir, are referenced
						// from the single .sln in the cur dir, then pick the sln
						proj_files = new string [0];
				}

				if (sln_files.Length + proj_files.Length > 1)
					ReportError (5, "Please specify the project or solution file " +
							"to build, as more than one solution or project file was found " +
							"in the current directory");

				if (sln_files.Length == 1)
					projectFile = sln_files [0];
				else
					projectFile = proj_files [0];
			} else if (remainingArguments.Count == 1) {
				projectFile = (string) remainingArguments [0];
			} else {
				ReportError (4, "Too many project files specified");
			}
		}

		private string UnquoteIfNeeded(string arg)
		{
			if (arg.StartsWith("\""))
				return arg.Substring(1, arg.Length - 2);
			return arg;
		}

		void LoadResponseFile (string filename)
		{
			StreamReader sr = null;
			string line;
			try {
				sr = new StreamReader (filename);
                                StringBuilder sb = new StringBuilder ();

                                while ((line = sr.ReadLine ()) != null) {
                                        int t = line.Length;

                                        for (int i = 0; i < t; i++) {
                                                char c = line [i];

						if (c == '#')
							// comment, ignore rest of the line
							break;

                                                if (c == '"' || c == '\'') {
                                                        char end = c;

                                                        for (i++; i < t; i++) {
                                                                c = line [i];

                                                                if (c == end)
                                                                        break;
                                                                sb.Append (c);
                                                        }
                                                } else if (c == ' ') {
                                                        if (sb.Length > 0) {
                                                                flatArguments.Add (sb.ToString ());
                                                                sb.Length = 0;
                                                        }
                                                } else
                                                        sb.Append (c);
                                        }
                                        if (sb.Length > 0){
                                                flatArguments.Add (sb.ToString ());
                                                sb.Length = 0;
                                        }
                                }
                        } catch (IOException x) {
				ErrorUtilities.ReportWarning (2, String.Format (
							"Error loading response file. (Exception: {0}). Ignoring.",
							x.Message));
			} finally {
                                if (sr != null)
                                        sr.Close ();
                        }
		}
		
		private bool ParseFlatArgument (string s)
		{
			switch (s) {
			case "/help":
			case "/h":
			case "/?":
				ErrorUtilities.ShowUsage ();
				break;
			case "/nologo":
				noLogo = true;
				break;
			case "/version":
			case "/ver":
				ErrorUtilities.ShowVersion (true);
				break;
			case "/noconsolelogger":
			case "/noconlog":
				noConsoleLogger = true;
				break;
			case "/validate":
			case "/val":
				validate = true;
				break;
			case "/fl":
			case "/filelogger":
				if (FileLoggerParameters [0] == null)
					FileLoggerParameters [0] = String.Empty;
				break;
			default:
				if (s.StartsWith ("/fl") && s.Length == 4 && Char.IsDigit (s[3])) {
					int index = Int32.Parse (s[3].ToString ());
					if (FileLoggerParameters [index] == null)
						FileLoggerParameters [index] = String.Empty;
				} else if (s.StartsWith ("/fileloggerparameters") || s.StartsWith ("/flp")) {
					ProcessFileLoggerParameters (s);
				} else if (s.StartsWith ("/target:") || s.StartsWith ("/t:")) {
					ProcessTarget (s);
				} else if (s.StartsWith ("/property:") || s.StartsWith ("/p:")) {
					if (!ProcessProperty (s))
						return false;
				} else  if (s.StartsWith ("/logger:") || s.StartsWith ("/l:")) {
					ProcessLogger (s);
				} else if (s.StartsWith ("/verbosity:") || s.StartsWith ("/v:")) {
					ProcessVerbosity (s);
				} else if (s.StartsWith ("/consoleloggerparameters:") || s.StartsWith ("/clp:")) {
					ProcessConsoleLoggerParameters (s);
				} else if (s.StartsWith ("/validate:") || s.StartsWith ("/val:")) {
					ProcessValidate (s);
				} else if (s.StartsWith ("/toolsversion:") || s.StartsWith ("/tv:")) {
					ToolsVersion = s.Split (':') [1];
				} else
					return false;
				break;
			}

			return true;
		}
		
		internal void ProcessTarget (string s)
		{
			TryProcessMultiOption (s, "Target names must be specified as /t:Target1;Target2",
						out targets);
		}
		
		internal bool ProcessProperty (string s)
		{
			string[] splitProperties;
			if (!TryProcessMultiOption (s, "Property name and value expected as /p:<prop name>=<prop value>",
						out splitProperties))
				return false;

			foreach (string st in splitProperties) {
				if (st.IndexOf ('=') < 0) {
					ReportError (5,
							"Invalid syntax. Property name and value expected as " +
							"<prop name>=[<prop value>]");
					return false;
				}
				string [] property = st.Split ('=');
				properties.Add (property [0], property.Length == 2 ? property [1] : "");
			}

			return true;
		}

Nuke.Common.Logger : Object

Fields :

public static LogLevel LogLevel

Methods :

public static Void Log(LogLevel level = , String text = null)
public static IDisposable Block(String text = )
public static Void Log(LogLevel level = , String format = , Object[] args = )
public static Void Log(LogLevel level = , Object value = )
public static Void Normal(String format = , Object[] args = )
public static Void Normal(Object value = )
public static Void Normal(String text = null)
public static Void Success(String format = , Object[] args = )
public static Void Success(Object value = )
public static Void Success(String text = null)
public static Void Trace(String format = , Object[] args = )
public static Void Trace(Object value = )
public static Void Trace(String text = null)
public static Void Info(String format = , Object[] args = )
public static Void Info(Object value = )
public static Void Info(String text = null)
public static Void Warn(String format = , Object[] args = )
public static Void Warn(Object value = )
public static Void Warn(String text = null)
public static Void Warn(Exception exception = )
public static Void Error(String format = , Object[] args = )
public static Void Error(Object value = )
public static Void Error(String text = null)
public static Void Error(Exception exception = )
public Type GetType()
public String ToString()
public Boolean Equals(Object obj = )
public Int32 GetHashCode()