drumkit-old/DrumKit/Log.cs

52 lines
1.5 KiB
C#
Raw Normal View History

2013-11-18 18:06:17 +00:00
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Storage;
namespace DrumKit
{
static class Log
{
public static async Task Initialize()
{
// Create "Logs" folder if not created
var folder = await ApplicationData.Current.RoamingFolder.CreateFolderAsync("AppLogs", CreationCollisionOption.OpenIfExists);
2013-11-18 18:11:53 +00:00
// Initialize the log repository
await Repository.LogRepository.Initialize(folder);
2013-11-18 18:06:17 +00:00
}
public static void Write(string format, params object[] args)
{
2013-11-18 18:11:53 +00:00
// Prepare data
2013-11-18 18:06:17 +00:00
string res = string.Format(format, args);
2013-11-18 18:11:53 +00:00
string final = string.Format("{0} INFO: {1}", DateTime.Now, res);
2013-11-18 18:06:17 +00:00
2013-11-18 18:11:53 +00:00
// Write
Repository.LogRepository.WriteLine(final);
2013-11-18 18:06:17 +00:00
}
public static void Error(string format, params object[] args)
{
2013-11-18 18:11:53 +00:00
// Prepare data
2013-11-18 18:06:17 +00:00
string res = string.Format(format, args);
2013-11-18 18:11:53 +00:00
string final = string.Format("{0} ERROR: {1}", DateTime.Now, res);
2013-11-18 18:06:17 +00:00
2013-11-18 18:11:53 +00:00
// Write
Repository.LogRepository.WriteLine(final);
2013-11-18 18:06:17 +00:00
}
public static void Except(Exception ex)
{
2013-11-18 18:11:53 +00:00
// Prepare data
string final = string.Format("{0} EXCEPTION: {1}", DateTime.Now, ex.ToString());
2013-11-18 18:06:17 +00:00
2013-11-18 18:11:53 +00:00
// Write
Repository.LogRepository.WriteLine(final);
2013-11-18 18:06:17 +00:00
}
}
}