forked from aspnet/AspNetWebStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormatterLoggerTraceWrapper.cs
More file actions
61 lines (55 loc) · 2.43 KB
/
FormatterLoggerTraceWrapper.cs
File metadata and controls
61 lines (55 loc) · 2.43 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
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Diagnostics.Contracts;
using System.Net.Http;
using System.Net.Http.Formatting;
namespace System.Web.Http.Tracing.Tracers
{
/// <summary>
/// FormatterLogger to trace an error while logging.
/// </summary>
internal class FormatterLoggerTraceWrapper : IFormatterLogger
{
private readonly IFormatterLogger _formatterLogger;
private readonly ITraceWriter _traceWriter;
private readonly HttpRequestMessage _request;
private readonly string _operatorName;
private readonly string _operationName;
public FormatterLoggerTraceWrapper(IFormatterLogger formatterLogger,
ITraceWriter traceWriter,
HttpRequestMessage request,
string operatorName,
string operationName)
{
Contract.Assert(formatterLogger != null);
Contract.Assert(traceWriter != null);
_formatterLogger = formatterLogger;
_traceWriter = traceWriter;
_request = request;
_operatorName = operatorName;
_operationName = operationName;
}
public void LogError(string errorPath, string errorMessage)
{
_traceWriter.Trace(_request, TraceCategories.FormattingCategory, TraceLevel.Error, (traceRecord) =>
{
traceRecord.Kind = TraceKind.Trace;
traceRecord.Operator = _operatorName;
traceRecord.Operation = _operationName;
traceRecord.Message = errorMessage;
});
_formatterLogger.LogError(errorPath, errorMessage);
}
public void LogError(string errorPath, Exception exception)
{
_traceWriter.Trace(_request, TraceCategories.FormattingCategory, TraceLevel.Error, (traceRecord) =>
{
traceRecord.Kind = TraceKind.Trace;
traceRecord.Operator = _operatorName;
traceRecord.Operation = _operationName;
traceRecord.Exception = exception;
});
_formatterLogger.LogError(errorPath, exception);
}
}
}