diff --git a/README.md b/README.md index 3c34a1e..24cc3b1 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ This is a C# .Net Core 2 ILogger implementation developed by **VTEX** developer * **Http** loggers available to send data via **Raw** or **Json** routes * **Socket** loggers available to send data via **TCP** or **UDP** * Send **Http** events as batch (Improve **Splunk** *HEC* performance sending data as batch) +* **ILoggerFormatter** that enable you to handle and formart your logs before send it to Splunk ### NuGet Package Status @@ -163,8 +164,16 @@ public class ValuesController : Controller [HttpGet] public IEnumerable Get() { - logger.LogCritical(new EventId(-1, "Values Controller"), new NotImplementedException(), "Error on GET api/values route"); - return new string[] { "value1", "value2" }; + var exception = new NotImplementedException(); + var message = "An error has ocurried route=Get"; + var eventId = new EventId(-1, "Values Controller"); + + //You can log like this + logger.Log(LogLevel.Trace, eventId, message, exception); + //Or like this + //logger.LogTrace(eventId, exception, message); + + return new string[] { "4", "2" }; } } ``` diff --git a/src/SampleWebAPI/Controllers/ValuesController.cs b/src/SampleWebAPI/Controllers/ValuesController.cs index 7051c16..5c78ddd 100644 --- a/src/SampleWebAPI/Controllers/ValuesController.cs +++ b/src/SampleWebAPI/Controllers/ValuesController.cs @@ -20,12 +20,14 @@ public ValuesController(ILoggerFactory loggerFactory) public IEnumerable Get() { var exception = new NotImplementedException(); - logger.Log(LogLevel.Trace, new EventId(-1, "Values Controller"), new { route = "Get" }, exception, - (argState, argException) => { - return string.Format("{0} {1}", - argState != null ? argState.ToString() : string.Empty, - argException != null ? argException.ToString() : string.Empty); - }); + var message = "An error has ocurried route=Get"; + var eventId = new EventId(-1, "Values Controller"); + + //You can log like this + logger.Log(LogLevel.Trace, eventId, message, exception); + //Or like this + logger.LogTrace(eventId, exception, message); + return new string[] { "4", "2" }; } } diff --git a/src/SampleWebAPI/SampleWebAPI.csproj b/src/SampleWebAPI/SampleWebAPI.csproj index 226589b..4f99550 100644 --- a/src/SampleWebAPI/SampleWebAPI.csproj +++ b/src/SampleWebAPI/SampleWebAPI.csproj @@ -2,7 +2,7 @@ netcoreapp2.0 - 1.1.1 + 1.1.2 Sample Web API project created to show how to use SplunkLogger library Splunk.SampleWebAPI diff --git a/src/SplunkLogger.sln b/src/SplunkLogger.sln index 84a8656..3707cb5 100644 --- a/src/SplunkLogger.sln +++ b/src/SplunkLogger.sln @@ -22,6 +22,6 @@ Global EndGlobalSection GlobalSection(MonoDevelopProperties) = preSolution description = C# .Net Core 2 Splunk ILogger Compatible Implementation - version = 1.1.1 + version = 1.1.2 EndGlobalSection EndGlobal diff --git a/src/SplunkLogger/ILoggerExtensions.cs b/src/SplunkLogger/ILoggerExtensions.cs new file mode 100644 index 0000000..1911e1f --- /dev/null +++ b/src/SplunkLogger/ILoggerExtensions.cs @@ -0,0 +1,16 @@ +using System; +using Microsoft.Extensions.Logging; + +namespace Splunk +{ + public static class ILoggerExtensions + { + public static void Log(this ILogger logger, LogLevel logLevel, EventId eventId, object message, Exception exception) + { + var stringMessage = string.Format("{0} {1}", + message != null ? message.ToString() : string.Empty, + exception != null ? exception.ToString() : string.Empty); + logger.Log(logLevel, eventId, message, exception, (s, e) => { return stringMessage; }); + } + } +} \ No newline at end of file diff --git a/src/SplunkLogger/SplunkLogger.csproj b/src/SplunkLogger/SplunkLogger.csproj index 6803fe3..afcb6a3 100644 --- a/src/SplunkLogger/SplunkLogger.csproj +++ b/src/SplunkLogger/SplunkLogger.csproj @@ -2,8 +2,8 @@ netcoreapp2.0 - 1.1.1 - 1.1.1 + 1.1.2 + 1.1.2 Splunk .Net Core ILogger Compatible Library Splunk Fábio Caldas