Exemple #1
0
        public TemporaryFileLogger()
        {
            FileStream fileStream = null;
            var        newLine    = Encoding.UTF8.GetBytes("\n");

            Receive <InitializeLogger>(_ =>
            {
                var exists = File.Exists("log.txt");

                if (exists)
                {
                    File.Delete("log.txt");
                }
                fileStream   = File.OpenWrite("log.txt");
                var preamble = Encoding.UTF8.GetPreamble();
                fileStream.Write(preamble, 0, preamble.Length);

                Sender.Reply(LoggerInitialized.Instance);
            });
            Receive <LogEvent>(e =>
            {
                var line  = LineLogFormatter.Format(e, LineLogFormatter.DefaultDateFormat);
                var bytes = Encoding.UTF8.GetBytes(line);
                fileStream.Write(bytes, 0, bytes.Length);
                fileStream.Write(newLine, 0, newLine.Length);
                fileStream.Flush();
            });
        }
Exemple #2
0
        public static void PrintError(ErrorLogEvent e, string dateFormat = DefaultDateFormat)
        {
            var msg = LineLogFormatter.FormatError(e, dateFormat);

            WriteLine(msg, LogLevel.Error);
        }
Exemple #3
0
        public static void PrintInfo(InfoLogEvent e, string dateFormat = DefaultDateFormat)
        {
            var msg = LineLogFormatter.FormatInfo(e, dateFormat);

            WriteLine(msg, LogLevel.Info);
        }
Exemple #4
0
        public static void PrintDebug(DebugLogEvent e, string dateFormat = DefaultDateFormat)
        {
            var msg = LineLogFormatter.FormatDebug(e, dateFormat);

            WriteLine(msg, LogLevel.Debug);
        }
Exemple #5
0
        public static void PrintWarning(WarningLogEvent e, string dateFormat = DefaultDateFormat)
        {
            var msg = LineLogFormatter.FormatWarning(e, dateFormat);

            WriteLine(msg, LogLevel.Warning);
        }