Statistics
| Branch: | Revision:

root / trunk / Pithos.Client.WPF / Caliburn / Micro / Logging / DebugLogger.cs @ 255f5f86

History | View | Annotate | Download (4.4 kB)

1
#region
2
/* -----------------------------------------------------------------------
3
 * <copyright file="DebugLogger.cs" company="GRNet">
4
 * 
5
 * Copyright 2011-2012 GRNET S.A. All rights reserved.
6
 *
7
 * Redistribution and use in source and binary forms, with or
8
 * without modification, are permitted provided that the following
9
 * conditions are met:
10
 *
11
 *   1. Redistributions of source code must retain the above
12
 *      copyright notice, this list of conditions and the following
13
 *      disclaimer.
14
 *
15
 *   2. Redistributions in binary form must reproduce the above
16
 *      copyright notice, this list of conditions and the following
17
 *      disclaimer in the documentation and/or other materials
18
 *      provided with the distribution.
19
 *
20
 *
21
 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
22
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
25
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
28
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
 * POSSIBILITY OF SUCH DAMAGE.
33
 *
34
 * The views and conclusions contained in the software and
35
 * documentation are those of the authors and should not be
36
 * interpreted as representing official policies, either expressed
37
 * or implied, of GRNET S.A.
38
 * </copyright>
39
 * -----------------------------------------------------------------------
40
 */
41
#endregion
42
using System;
43
using System.Diagnostics;
44

    
45
namespace Caliburn.Micro.Logging
46
{
47
  /// <summary>
48
  /// Implementation of the ILog and ILogExtended interfaces using
49
  /// <see cref="Debug"/>.
50
  /// </summary>
51
  public class DebugLogger : ILog//, ILogExtended
52
  {
53
    #region Constants
54
    private const string ErrorText = "ERROR";
55
    private const string WarnText = "WARN";
56
    private const string InfoText = "INFO";
57
    #endregion
58

    
59
    #region Fields
60
    private readonly Type _type;
61
    #endregion
62
    
63
    #region Constructors
64
    public DebugLogger(Type type)
65
    {
66
      _type = type;
67
    }
68
    #endregion
69
    
70
    #region Helper Methods
71
    private string CreateLogMessage(string format, params object[] args)
72
    {
73
      return string.Format("[{0}] {1}", DateTime.Now.ToString("o"), string.Format(format, args));
74
    }
75
    #endregion
76
    
77
    #region ILog Members
78
    /// <summary>
79
    /// Logs the exception.
80
    /// </summary>
81
    /// <param name="exception">The exception.</param>
82
    public void Error(Exception exception)
83
    {
84
      Debug.WriteLine(CreateLogMessage(exception.ToString()), ErrorText);
85
    }
86
    /// <summary>
87
    /// Logs the message as info.
88
    /// </summary>
89
    /// <param name="format">A formatted message.</param><param name="args">Parameters to be injected into the formatted message.</param>
90
    public void Info(string format, params object[] args)
91
    {
92
      Debug.WriteLine(CreateLogMessage(format, args), InfoText);
93
    }
94
    /// <summary>
95
    /// Logs the message as a warning.
96
    /// </summary>
97
    /// <param name="format">A formatted message.</param><param name="args">Parameters to be injected into the formatted message.</param>
98
    public void Warn(string format, params object[] args)
99
    {
100
      Debug.WriteLine(CreateLogMessage(format, args), WarnText);
101
    }
102
    #endregion
103

    
104
    #region Implementation of ILogExtended
105
    /// <summary>
106
    /// Logs the message as error.
107
    /// </summary>
108
    /// <param name="format">A formatted message.</param>
109
    /// <param name="args">Parameters to be injected into the formatted message.</param>
110
    public void Error(string format, params object[] args)
111
    {
112
      Debug.WriteLine(CreateLogMessage(format, args), ErrorText);
113
    }
114
    /// <summary>
115
    /// Logs the exception.
116
    /// </summary>
117
    /// <param name="exception">The exception.</param>
118
    /// <param name="format">A formatted message.</param>
119
    /// <param name="args">Parameters to be injected into the formatted message.</param>
120
    public void Error(Exception exception, string format, params object[] args)
121
    {
122
      Debug.WriteLine(CreateLogMessage(format + " - Exception = " + exception.ToString(), args), ErrorText);
123
    }
124
    #endregion
125
  }
126
}