Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

Commit 6bb6947

Browse files
committed
Adding a Message property to ILoggerStructure
1 parent 4ba41aa commit 6bb6947

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

src/Microsoft.Framework.Logging.Console/ConsoleLogger.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@ public void Write(LogLevel logLevel, int eventId, object state, Exception except
3131
return;
3232
}
3333
var message = string.Empty;
34-
if (state is ILoggerStructure)
34+
var structure = state as ILoggerStructure;
35+
if (structure != null)
3536
{
3637
var builder = new StringBuilder();
3738
FormatLoggerStructure(
3839
builder,
39-
(ILoggerStructure)state,
40+
structure,
4041
level: 1,
4142
bullet: false);
4243
message = Convert.ToString(builder.ToString(), CultureInfo.InvariantCulture);
@@ -115,6 +116,10 @@ public IDisposable BeginScope(object state)
115116

116117
private void FormatLoggerStructure(StringBuilder builder, ILoggerStructure structure, int level, bool bullet)
117118
{
119+
if (structure.Message != null)
120+
{
121+
builder.Append(structure.Message);
122+
}
118123
var values = structure.GetValues();
119124
if (values == null)
120125
{

src/Microsoft.Framework.Logging.Interfaces/ILoggerStructure.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
1+
using System.Collections.Generic;
32

43
namespace Microsoft.Framework.Logging
54
{
@@ -8,6 +7,14 @@ namespace Microsoft.Framework.Logging
87
#endif
98
public interface ILoggerStructure
109
{
10+
/// <summary>
11+
/// A brief message to give context for the structure being logged
12+
/// </summary>
13+
string Message { get; }
14+
15+
/// <summary>
16+
/// Returns an enumerable of key value pairs mapping the name of the structured data to the data.
17+
/// </summary>
1118
IEnumerable<KeyValuePair<string, object>> GetValues();
1219

1320
/// <summary>

src/Microsoft.Framework.Logging/LoggerStructureBase.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ namespace Microsoft.Framework.Logging
55
{
66
public abstract class LoggerStructureBase : ILoggerStructure
77
{
8+
public string Message { get; set; }
9+
810
public virtual IEnumerable<KeyValuePair<string, object>> GetValues()
911
{
1012
var values = new List<KeyValuePair<string, object>>();

0 commit comments

Comments
 (0)