-
Notifications
You must be signed in to change notification settings - Fork 358
/
TraceWriter.cs
89 lines (80 loc) · 3.26 KB
/
TraceWriter.cs
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
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
using System;
using System.Diagnostics;
namespace Microsoft.Azure.WebJobs.Host
{
/// <summary>
/// Base class for trace writers used by the <see cref="JobHost"/> for
/// event tracing. See <see cref="JobHostConfiguration.Tracing"/> for details.
/// </summary>
public abstract class TraceWriter
{
/// <summary>
/// Constructs a new instance.
/// </summary>
/// <param name="level">The <see cref="TraceLevel"/> used to filter trace events.</param>
protected TraceWriter(TraceLevel level)
{
Level = level;
}
/// <summary>
/// Gets or sets the <see cref="TraceLevel"/> filter used to filter trace events.
/// Only trace events with a <see cref="TraceLevel"/> less than or equal to
/// this level will be traced.
/// <remarks>
/// Level filtering will be done externally by the <see cref="JobHost"/>, so
/// it shouldn't be done by this class.
/// </remarks>
/// </summary>
public TraceLevel Level { get; set; }
/// <summary>
/// Writes a trace event.
/// </summary>
/// <param name="traceEvent">The <see cref="TraceEvent"/> to trace.</param>
public abstract void Trace(TraceEvent traceEvent);
/// <summary>
/// Writes a <see cref="TraceLevel.Verbose"/> level trace event.
/// </summary>
/// <param name="message">The trace message.</param>
/// <param name="source">The source of the message.</param>
public void Verbose(string message, string source = null)
{
Trace(new TraceEvent(TraceLevel.Verbose, message, source));
}
/// <summary>
/// Writes a <see cref="TraceLevel.Info"/> level trace event.
/// </summary>
/// <param name="message">The trace message.</param>
/// <param name="source">The source of the message.</param>
public void Info(string message, string source = null)
{
Trace(new TraceEvent(TraceLevel.Info, message, source));
}
/// <summary>
/// Writes a <see cref="TraceLevel.Warning"/> level trace event.
/// </summary>
/// <param name="message">The trace message.</param>
/// <param name="source">The source of the message.</param>
public void Warning(string message, string source = null)
{
Trace(new TraceEvent(TraceLevel.Warning, message, source));
}
/// <summary>
/// Writes a <see cref="TraceLevel.Error"/> level trace event.
/// </summary>
/// <param name="message">The trace message.</param>
/// <param name="ex">The optional <see cref="Exception"/> for the error.</param>
/// <param name="source">The source of the message.</param>
public void Error(string message, Exception ex = null, string source = null)
{
Trace(new TraceEvent(TraceLevel.Error, message, source, ex));
}
/// <summary>
/// Flush any buffered trace events.
/// </summary>
public virtual void Flush()
{
}
}
}