aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Logging/SimpleStringLogger.cs
blob: 5d9b12d816f76e48e0610fa82d94b9ad6124d177 (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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Tango.Logging
{
    public class SimpleStringLogger : ILogger
    {
        private bool _enabled;

        public bool Enabled { get => _enabled; set => _enabled = value; }

        public List<LogCategory> Categories { get; set; }

        public event EventHandler<LogItemBase> LogReceived;

        public SimpleStringLogger()
        {
            Categories = new List<LogCategory>();
            Categories.Add(LogCategory.Critical);
            Categories.Add(LogCategory.Debug);
            Categories.Add(LogCategory.Error);
            Categories.Add(LogCategory.Info);
            Categories.Add(LogCategory.Warning);
            Enabled = true;
        }

        public SimpleStringLogger(params LogCategory[] categories) : this()
        {
            Categories = categories.ToList();
        }

        public void OnLog(LogItemBase log)
        {
            if (Categories.Contains(log.Category))
            {
                LogReceived?.Invoke(this, log);
            }
        }
    }
}