Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Logger into file
static readonly string loggerPath = Path.Combine(Environment.CurrentDirectory, "Log.txt");
public static void Logger(string log)
{
try
{
File.AppendAllText(loggerPath, log + "\n");
}
catch (IOException ex)
{
Console.WriteLine($"При логировании сообщения: \"{log}\" " +
$"произошла ошибка: {ex.Message}");
}
catch (UnauthorizedAccessException ex)
{
Console.WriteLine($"Ошибка доступа: {ex.Message}");
}
catch (Exception ex)
{
Console.WriteLine($"Непредвиденная ошибка: ${ex.Message}");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment