예제 #1
0
파일: Program.cs 프로젝트: sschmid/NLog
 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);
     });
 }
예제 #2
0
        void Awake()
        {
            _socket = new SocketAppender();
            _defaultFormatter = new DefaultLogMessageFormatter();
            _timestampFormatter = new TimestampFormatter();
            _colorFormatter = new ColorCodeFormatter();

            if (cacheLogsWhenNotConnected) {
                LoggerFactory.AddAppender(send);
            }
        }
예제 #3
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);
        }
예제 #4
0
파일: Program.cs 프로젝트: sschmid/NLog
 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);
     });
 }
예제 #5
0
파일: Program.cs 프로젝트: sschmid/NLog
        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);
        }
예제 #6
0
파일: Program.cs 프로젝트: sschmid/NLog
        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);
        }
예제 #7
0
파일: Program.cs 프로젝트: sschmid/NLog
        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);
        }
예제 #8
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);
        }
    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");
        };
    }
예제 #10
0
 void Awake()
 {
     _fileWriter = new FileWriter(filePath);
     _defaultFormatter = new DefaultLogMessageFormatter();
     _timestampFormatter = new TimestampFormatter();
 }