diff --git a/SimpleTGBot/Logging/FileSink.cs b/SimpleTGBot/Logging/FileSink.cs new file mode 100644 index 0000000..411b49f --- /dev/null +++ b/SimpleTGBot/Logging/FileSink.cs @@ -0,0 +1,22 @@ +namespace SimpleTGBot.Logging; + +internal class FileSink : ILogSink +{ + StreamWriter file; + + public FileSink(string filename) + { + file = new StreamWriter(filename, true); + } + + public void Log(DateTime time, LogLevel level, string message) + { + foreach (string line in message.Split(Environment.NewLine)) + file.WriteLine($"({time:u}) [{level.GetName()}] {line}"); + } + + public void Dispose() + { + file.Dispose(); + } +} diff --git a/SimpleTGBot/Program.cs b/SimpleTGBot/Program.cs index 71c6b3f..45b7e8f 100644 --- a/SimpleTGBot/Program.cs +++ b/SimpleTGBot/Program.cs @@ -39,6 +39,7 @@ public static class Program using (Logger logger = new Logger()) { logger.Sinks.Add(new StdoutSink()); + logger.Sinks.Add(new FileSink("dembot.log")); TelegramBot telegramBot = new TelegramBot(botToken, logger, db); await telegramBot.Run(); }