aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Logging/VSOutputLogger.cs
blob: a39f14593cf0d51f793753978d49111fdc5817a1 (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
45
46
47
48
49
50
51
52
53
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Tango.Logging
{
    /// <summary>
    /// Represents a library logger for routing logs to the Visual Studio output window.
    /// </summary>
    public class VSOutputLogger : ILogger
    {
        private String _assembly_name;

        /// <summary>
        /// Initializes a new instance of the <see cref="VSOutputLogger"/> class.
        /// </summary>
        public VSOutputLogger(String projectName = null)
        {
            Enabled = true;

            _assembly_name = projectName != null ? projectName : Assembly.GetEntryAssembly().GetName().Name + ": ";
        }

        /// <summary>
        /// Called when a new library trace is available.
        /// </summary>
        /// <param name="output">The output.</param>
        public void OnLog(LogItemBase output)
        {
            Debug.WriteLine(_assembly_name + output.ToString());
        }

        private bool _isEnabled;
        /// <summary>
        /// Gets or sets a value indicating whether this <see cref="ILogger" /> is enabled.
        /// </summary>
        public bool Enabled
        {
            get
            {
                return _isEnabled;
            }
            set
            {
                _isEnabled = value;
            }
        }
    }
}