Skip to content

Instantly share code, notes, and snippets.

@UweKeim
Last active September 5, 2019 16:09
Show Gist options
  • Save UweKeim/58a65b42cb4481eac4ed to your computer and use it in GitHub Desktop.
Save UweKeim/58a65b42cb4481eac4ed to your computer and use it in GitHub Desktop.
The shortest possible file logging class.
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