Пример #1
0
        void setupNLog(MyErrorReporter myErrorReporter)
        {
            LoggerFactory.globalLogLevel = LogLevel.On;

            // Add appender to print messages with Console.WriteLine
            LoggerFactory.AddAppender((logger, logLevel, message) => Console.WriteLine(message));

            // Add another appender to write messages to a file
            var fileWriter = new FileWriter("Log.txt");
            LoggerFactory.AddAppender((logger, logLevel, message) => fileWriter.WriteLine(message));

            // Or simply create your own custom appender, e.g.
            // a custom error reporter, which only sends messages
            // if the log level is at least 'error'
            LoggerFactory.AddAppender((logger, logLevel, message) => {
                if (logLevel >= LogLevel.Error) {
                    myErrorReporter.Send(logLevel + " " + message);
                }
            });
        }
Пример #2
0
        void setupNLog(MyErrorReporter myErrorReporter)
        {
            LoggerFactory.globalLogLevel = LogLevel.On;

            // Add appender to print messages with Console.WriteLine
            LoggerFactory.AddAppender((logger, logLevel, message) => Console.WriteLine(message));

            // Add another appender to write messages to a file
            var fileWriter = new FileWriter("Log.txt");

            LoggerFactory.AddAppender((logger, logLevel, message) => fileWriter.WriteLine(message));

            // Or simply create your own custom appender, e.g.
            // a custom error reporter, which only sends messages
            // if the log level is at least 'error'
            LoggerFactory.AddAppender((logger, logLevel, message) => {
                if (logLevel >= LogLevel.Error)
                {
                    myErrorReporter.Send(logLevel + " " + message);
                }
            });
        }