Last active
September 5, 2019 16:09
-
-
Save UweKeim/58a65b42cb4481eac4ed to your computer and use it in GitHub Desktop.
The shortest possible file logging class.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Helper | |
{ | |
using System; | |
using System.IO; | |
using System.Reflection; | |
/// <summary> | |
/// The shortest possible logger. | |
/// </summary> | |
public static class QuickLogger | |
{ | |
private static readonly Lazy<string> LogFilePath = new Lazy<string>(() => | |
{ | |
var folderPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal); | |
var fileName = Path.ChangeExtension(Path.GetFileName(Assembly.GetEntryAssembly().Location), @".log"); | |
return Path.Combine(folderPath, fileName); | |
}); | |
public static void Log(string text, params object[] args) | |
{ | |
if (!string.IsNullOrEmpty(text)) | |
{ | |
var msg = string.Format(@"[{0}, {1}\{2}] {3}" + Environment.NewLine, | |
DateTime.Now, | |
Environment.UserDomainName, | |
Environment.UserName, | |
string.Format(text, args)); | |
File.AppendAllText(LogFilePath.Value, msg); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment