Skip to content

Commit 346aac9

Browse files
committed
Improved sample log code with a formatter
#39
1 parent 9bef9c8 commit 346aac9

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/SampleWebAPI/Controllers/ValuesController.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ public ValuesController(ILoggerFactory loggerFactory)
2020
public IEnumerable<string> Get()
2121
{
2222
var exception = new NotImplementedException();
23-
logger.Log(LogLevel.Critical,
24-
new EventId(-1, "Values Controller"),
25-
new { route = "Get" },
26-
exception, null);
27-
throw exception;
23+
logger.Log(LogLevel.Critical, new EventId(-1, "Values Controller"), new { route = "Get" }, exception,
24+
(argState, argException) => {
25+
return string.Format("{0} {1}",
26+
argState != null ? argState.ToString() : string.Empty,
27+
argException != null ? argException.ToString() : string.Empty);
28+
});
29+
return new string[] { "4", "2" };
2830
}
2931
}
3032
}

0 commit comments

Comments
 (0)