-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTraceLog.cs
More file actions
101 lines (91 loc) · 2.96 KB
/
TraceLog.cs
File metadata and controls
101 lines (91 loc) · 2.96 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
*
* MvxLib, an open source C# library used for communication with Intentia Movex.
* http://mvxlib.sourceforge.net
*
* Copyright (C) 2005 - 2007 Mattias Bengtsson
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
using System;
namespace MvxLib
{
/// <summary>
/// A simple logging-class.
/// </summary>
public class TraceLog
{
private System.Collections.ArrayList _entries = new System.Collections.ArrayList();
private long previous_tick = DateTime.Now.Ticks;
/// <summary>
/// Returns an array of all TraceLog entries.
/// </summary>
public TraceLogEntry[] Entries
{
get { return (TraceLogEntry[]) _entries.ToArray(typeof (TraceLogEntry)); }
}
/// <returns>All TraceLogEntries concatenated.</returns>
public override string ToString()
{
string ret = string.Empty;
for (int i = 0; i < Entries.Length; i++)
ret += Entries[i].ToString() + Environment.NewLine;
return ret;
}
/// <summary>
/// Add a TraceLogEntry to the log.
/// </summary>
/// <param name="message">The message of the trace.</param>
public void WriteTrace(string message)
{
_entries.Add(new TraceLogEntry(message, DateTime.Now.Ticks - previous_tick));
previous_tick = DateTime.Now.Ticks;
}
/// <summary>
/// Add a TraceLogEntry to the log.
/// </summary>
/// <param name="ex">The exception to log to the trace.</param>
public void WriteTrace(Exception ex)
{
WriteTrace("Exception: " + ex.ToString());
}
/// <summary>
/// Struct containing the actual tracelog-messages.
/// </summary>
public struct TraceLogEntry
{
DateTime TimeOfEntry;
long ElapsedTicks;
string Message;
/// <summary>
/// Enter an entry to the log.
/// </summary>
/// <param name="message">Message of the entry.</param>
/// <param name="elapsed_ticks">Ticks elapsed since the last log was entered.</param>
public TraceLogEntry(string message, long elapsed_ticks)
{
TimeOfEntry = DateTime.Now;
ElapsedTicks = elapsed_ticks;
Message = message;
}
/// <returns>A string suitable for storing.</returns>
public override string ToString()
{
return TimeOfEntry.ToString() + " " + ElapsedTicks.ToString().PadRight(10) + Message;
}
}
}
}