summaryrefslogtreecommitdiff
path: root/code/common/Logging.cs
blob: 4afa6319c560d135625e28253c87869c33867534 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System;
using System.IO;
using System.Reflection;

namespace common
{
    static public class Logging
    {
        static public Logger log<T>(this T item)
        {
            return new TextLogger(Console.Out);
        }

        static public void log(this string item, params object[] arguments)
        {
            new TextLogger(Console.Out).debug(item, arguments);
        }

        static public void add_to_log(this Exception item)
        {
            new TextLogger(Console.Out).debug(item.Message);
        }
    }

    public class TextLogger : Logger
    {
        readonly TextWriter writer;

        public TextLogger(TextWriter writer)
        {
            this.writer = writer;
        }

        public void debug(string message, params object[] arguments)
        {
            writer.WriteLine("{0}: {1}".format(Assembly.GetEntryAssembly().GetName().Name, message.format(arguments)));
        }
    }

    public interface Logger
    {
        void debug(string message, params object[] arguments);
    }
}