using System;
using System.Collections.Concurrent;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace StardewModdingAPI
{
public static class Log
{
private static readonly LogWriter _writer;
static Log()
{
_writer = LogWriter.Instance;
}
private static void PrintLog(LogInfo li)
{
_writer.WriteToLog(li);
}
#region Sync Logging
///
/// NOTICE: Sync logging is discouraged. Please use Async instead.
///
/// Message to log
/// Colour of message
public static void SyncColour(object message, ConsoleColor colour)
{
PrintLog(new LogInfo(message?.ToString(), colour));
}
#endregion
///
/// Catch unhandled exception from the application
///
/// Should be moved out of here if we do more than just log the exception.
public static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
Console.WriteLine("An exception has been caught");
File.WriteAllText(Constants.LogDir + "\\MODDED_ErrorLog.Log_" + DateTime.UtcNow.Ticks + ".txt", e.ExceptionObject.ToString());
}
///
/// Catch thread exception from the application
///
/// Should be moved out of here if we do more than just log the exception.
public static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
{
Console.WriteLine("A thread exception has been caught");
File.WriteAllText(Constants.LogDir + "\\MODDED_ErrorLog.Log_" + Extensions.Random.Next(100000000, 999999999) + ".txt", e.Exception.ToString());
}
#region Async Logging
public static void AsyncColour(object message, ConsoleColor colour)
{
Task.Run(() => { PrintLog(new LogInfo(message?.ToString(), colour)); });
}
public static void Async(object message)
{
AsyncColour(message?.ToString(), ConsoleColor.Gray);
}
public static void AsyncR(object message)
{
AsyncColour(message?.ToString(), ConsoleColor.Red);
}
public static void AsyncO(object message)
{
AsyncColour(message.ToString(), ConsoleColor.DarkYellow);
}
public static void AsyncY(object message)
{
AsyncColour(message?.ToString(), ConsoleColor.Yellow);
}
public static void AsyncG(object message)
{
AsyncColour(message?.ToString(), ConsoleColor.Green);
}
public static void AsyncC(object message)
{
AsyncColour(message?.ToString(), ConsoleColor.Cyan);
}
public static void AsyncM(object message)
{
AsyncColour(message?.ToString(), ConsoleColor.Magenta);
}
#endregion
#region ToRemove
public static void LogValueNotSpecified()
{
AsyncR(" must be specified");
}
public static void LogObjectValueNotSpecified()
{
AsyncR("