示例#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 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);
                }
            });
        }
示例#3
0
 void Awake()
 {
     _fileWriter = new FileWriter(filePath);
     _defaultFormatter = new DefaultLogMessageFormatter();
     _timestampFormatter = new TimestampFormatter();
 }