mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-08-18 13:31:41 +02:00
.github
.idea
Application
DialogHandler.cs
Logger.cs
SystemHandler.cs
Browser
Configuration
Controls
Dialogs
Management
Plugins
Properties
Resources
Updates
Utils
bld
lib
subprocess
video
.gitattributes
.gitignore
LICENSE.md
Program.cs
README.md
Reporter.cs
TweetDuck.csproj
TweetDuck.sln
TweetDuck.sln.DotSettings
Version.cs
app.config
packages.config
69 lines
1.5 KiB
C#
69 lines
1.5 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Text;
|
|
using TweetLib.Core;
|
|
using TweetLib.Core.Application;
|
|
|
|
namespace TweetDuck.Application {
|
|
sealed class Logger : IAppLogger {
|
|
private string LogFilePath => Path.Combine(App.StoragePath, logFileName);
|
|
|
|
private readonly string logFileName;
|
|
|
|
public Logger(string logFileName) {
|
|
this.logFileName = logFileName;
|
|
}
|
|
|
|
bool IAppLogger.Debug(string message) {
|
|
#if DEBUG
|
|
return Log("DEBUG", message);
|
|
#else
|
|
return Arguments.HasFlag(Arguments.ArgLogging) && Log(message);
|
|
#endif
|
|
}
|
|
|
|
bool IAppLogger.Info(string message) {
|
|
return Log("INFO", message);
|
|
}
|
|
|
|
bool IAppLogger.Error(string message) {
|
|
return Log("ERROR", message);
|
|
}
|
|
|
|
bool IAppLogger.OpenLogFile() {
|
|
try {
|
|
using (Process.Start(LogFilePath)) {}
|
|
} catch (Exception) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
private bool Log(string level, string message) {
|
|
#if DEBUG
|
|
Debug.WriteLine("[" + level + "] " + message);
|
|
#endif
|
|
|
|
string logFilePath = LogFilePath;
|
|
|
|
StringBuilder build = new StringBuilder();
|
|
|
|
if (!File.Exists(logFilePath)) {
|
|
build.Append("Please, report all issues to: https://github.com/chylex/TweetDuck/issues\r\n\r\n");
|
|
}
|
|
|
|
build.Append("[").Append(DateTime.Now.ToString("G", Lib.Culture)).Append("]\r\n");
|
|
build.Append(message).Append("\r\n\r\n");
|
|
|
|
try {
|
|
File.AppendAllText(logFilePath, build.ToString(), Encoding.UTF8);
|
|
return true;
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|