Exemple #1
0
        private void SetupLogger()
        {
            var defaultFormatter   = new DefaultLogMessageFormatter();
            var timestampFormatter = new TimestampFormatter();

            LoggerFactory.AddAppender((logger, logLevel, message) => {
                message = defaultFormatter.FormatMessage(logger, logLevel, message);
                message = timestampFormatter.FormatMessage(logger, logLevel, message);
                switch (logLevel)
                {
                case LogLevel.On:
                case LogLevel.Trace:
                case LogLevel.Debug:
                case LogLevel.Info:
                    Debug.Log(message);
                    break;

                case LogLevel.Warn:
                    Debug.LogWarning(message);
                    break;

                case LogLevel.Error:
                case LogLevel.Fatal:
                    Debug.LogError(message);
                    break;

                case LogLevel.Off:
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(logLevel), logLevel, null);
                }
            });
        }
Exemple #2
0
 void send(LoggerSet logger, LogLevelSet logLevel, string message)
 {
     message = _defaultFormatter.FormatMessage(logger, logLevel, message);
     message = _timestampFormatter.FormatMessage(logger, logLevel, message);
     message = _colorFormatter.FormatMessage(logLevel, message);
     _socket.Send(logLevel, message);
 }
    void when_created()
    {
        it["formats string"] = () => {
            var f       = new DefaultLogMessageFormatter();
            var logger  = new Logger("MyLogger");
            var message = f.FormatMessage(logger, LogLevel.Debug, "hi");
            message.should_be("[DEBUG] MyLogger: hi");
        };

        it["pads logLevel"] = () => {
            var f        = new DefaultLogMessageFormatter();
            var logger   = new Logger("MyLogger");
            var message1 = f.FormatMessage(logger, LogLevel.Debug, "hi");
            var message2 = f.FormatMessage(logger, LogLevel.Warn, "hi");
            message1.should_be("[DEBUG] MyLogger: hi");
            message2.should_be("[WARN]  MyLogger: hi");
        };
    }
Exemple #4
0
        void setupSOSMaxAppender()
        {
            var defaultFormatter = new DefaultLogMessageFormatter();
            var socket           = new SOSMaxAppender();

            LoggerFactory.AddAppender(((logger, logLevel, message) => {
                message = defaultFormatter.FormatMessage(logger, logLevel, message);
                socket.Send(logLevel, message);
            }));

            socket.Connect(IPAddress.Loopback, 4444);
        }
Exemple #5
0
        static void fileWriterTest()
        {
            var fileWriter = new FileWriter("Log.txt");

            fileWriter.ClearFile();
            var formatter = new DefaultLogMessageFormatter();

            LoggerFactory.AddAppender((logger, logLevel, message) => {
                var logMessage = formatter.FormatMessage(logger, logLevel, message);
                fileWriter.WriteLine(logMessage);
            });
        }
Exemple #6
0
        static void consoleLogTest()
        {
            var defaultFormatter   = new DefaultLogMessageFormatter();
            var timestampFormatter = new TimestampFormatter();
            var colorFormatter     = new ColorCodeFormatter();

            LoggerFactory.AddAppender((logger, logLevel, message) => {
                message = defaultFormatter.FormatMessage(logger, logLevel, message);
                message = timestampFormatter.FormatMessage(logger, logLevel, message);
                message = colorFormatter.FormatMessage(logLevel, message);
                Console.WriteLine(message);
            });
        }
Exemple #7
0
        static void serverSocketTest()
        {
            var formatter      = new DefaultLogMessageFormatter();
            var colorFormatter = new ColorCodeFormatter();
            var socket         = new SocketAppender();

            LoggerFactory.AddAppender(((logger, logLevel, message) => {
                var logMessage = formatter.FormatMessage(logger, logLevel, message);
                var coloredLogMessage = colorFormatter.FormatMessage(logLevel, logMessage);
                socket.Send(logLevel, coloredLogMessage);
            }));

            socket.Listen(1234);
        }
Exemple #8
0
        static void clientSocketTest()
        {
            var defaultFormatter = new DefaultLogMessageFormatter();
            var socket           = new SOSMaxAppender();

            LoggerFactory.AddAppender(((logger, logLevel, message) => {
                message = defaultFormatter.FormatMessage(logger, logLevel, message);
                socket.Send(logLevel, message);
            }));

            socket.Connect(IPAddress.Loopback, 4444);

            Thread.Sleep(50);
        }
Exemple #9
0
        static void clientSocketTest()
        {
            var formatter      = new DefaultLogMessageFormatter();
            var colorFormatter = new ColorCodeFormatter();
            var socket         = new SocketAppender();

            LoggerFactory.AddAppender(((logger, logLevel, message) => {
                var logMessage = formatter.FormatMessage(logger, logLevel, message);
                var coloredLogMessage = colorFormatter.FormatMessage(logLevel, logMessage);
                socket.Send(logLevel, coloredLogMessage);
            }));

            Log.Trace("History");
            socket.Connect(IPAddress.Loopback, 1234);
            Thread.Sleep(50);
        }
Exemple #10
0
        void setupExamaple()
        {
            // Setup appender
            var defaultFormatter = new DefaultLogMessageFormatter();
            var colorFormatter   = new ColorCodeFormatter();
            var socket           = new SocketAppender();

            LoggerFactory.AddAppender(((logger, logLevel, message) => {
                message = defaultFormatter.FormatMessage(logger, logLevel, message);
                message = colorFormatter.FormatMessage(logLevel, message);
                socket.Send(logLevel, message);
            }));

            // Setup as client
            socket.Connect(IPAddress.Loopback, 1234);

            // Or setup as server
            // socket.Listen(1234);
        }
Exemple #11
0
 void write(Logger logger, LogLevel logLevel, string message)
 {
     message = _defaultFormatter.FormatMessage(logger, logLevel, message);
     message = _timestampFormatter.FormatMessage(logger, logLevel, message);
     _fileWriter.WriteLine(message);
 }