Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/improve usability #63

Merged
merged 4 commits into from
Apr 20, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/SampleWebAPI/Controllers/ValuesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ public ValuesController(ILoggerFactory loggerFactory)
public IEnumerable<string> 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" };
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/SampleWebAPI/SampleWebAPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<ReleaseVersion>1.1.1</ReleaseVersion>
<ReleaseVersion>1.1.2</ReleaseVersion>
<Description>Sample Web API project created to show how to use SplunkLogger library</Description>
<RootNamespace>Splunk.SampleWebAPI</RootNamespace>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/SplunkLogger.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 16 additions & 0 deletions src/SplunkLogger/ILoggerExtensions.cs
Original file line number Diff line number Diff line change
@@ -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; });
}
}
}
4 changes: 2 additions & 2 deletions src/SplunkLogger/SplunkLogger.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<ReleaseVersion>1.1.1</ReleaseVersion>
<Version>1.1.1</Version>
<ReleaseVersion>1.1.2</ReleaseVersion>
<Version>1.1.2</Version>
<Description>Splunk .Net Core ILogger Compatible Library</Description>
<RootNamespace>Splunk</RootNamespace>
<Authors>Fábio Caldas</Authors>
Expand Down