Skip to content

Commit ad47d43

Browse files
authored
Merge pull request #49 from vtex/feature/code_improvement
Feature/code improvement
2 parents 44ab03d + 679fcae commit ad47d43

15 files changed

+81
-116
lines changed

src/SampleWebAPI/Controllers/ValuesController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using Microsoft.AspNetCore.Mvc;
44
using Microsoft.Extensions.Logging;
55

6-
namespace Vtex.SampleWebAPI.Controllers
6+
namespace Splunk.SampleWebAPI.Controllers
77
{
88
[Route("api/[controller]")]
99
public class ValuesController : Controller
@@ -20,7 +20,7 @@ public ValuesController(ILoggerFactory loggerFactory)
2020
public IEnumerable<string> Get()
2121
{
2222
var exception = new NotImplementedException();
23-
logger.Log(LogLevel.Critical, new EventId(-1, "Values Controller"), new { route = "Get" }, exception,
23+
logger.Log(LogLevel.Trace, new EventId(-1, "Values Controller"), new { route = "Get" }, exception,
2424
(argState, argException) => {
2525
return string.Format("{0} {1}",
2626
argState != null ? argState.ToString() : string.Empty,

src/SampleWebAPI/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using Microsoft.AspNetCore;
22
using Microsoft.AspNetCore.Hosting;
33

4-
namespace Vtex.SampleWebAPI
4+
namespace Splunk.SampleWebAPI
55
{
66
public class Program
77
{

src/SampleWebAPI/SampleWebAPI.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
<TargetFramework>netcoreapp2.0</TargetFramework>
55
<ReleaseVersion>1.0.5</ReleaseVersion>
66
<Description>Sample Web API project created to show how to use SplunkLogger library</Description>
7-
<RootNamespace>Vtex.SampleWebAPI</RootNamespace>
7+
<RootNamespace>Splunk.SampleWebAPI</RootNamespace>
88
</PropertyGroup>
99

1010
<ItemGroup>
1111
<Folder Include="wwwroot\" />
1212
</ItemGroup>
1313

1414
<ItemGroup>
15-
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
15+
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.5" />
1616
</ItemGroup>
1717

1818
<ItemGroup>

src/SampleWebAPI/Startup.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
using Microsoft.Extensions.DependencyInjection;
55
using Microsoft.Extensions.Logging;
66
using Microsoft.Extensions.Options;
7-
using Splunk;
87
using Splunk.Configurations;
98

10-
namespace Vtex.SampleWebAPI
9+
namespace Splunk.SampleWebAPI
1110
{
1211
public class Startup
1312
{
@@ -36,13 +35,15 @@ public void ConfigureServices(IServiceCollection services)
3635
/// <param name="loggerFactory">Logger factory.</param>
3736
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
3837
{
39-
//loggerFactory.AddDebug();
40-
41-
var splunkLoggerConfigurationOption = app.ApplicationServices.GetService<IOptions<SplunkLoggerConfiguration>>();
42-
38+
4339
/******************************** Define Your Logger *********************************/
4440
/* */
45-
loggerFactory.AddHECRawSplunkLogger(splunkLoggerConfigurationOption.Value); //
41+
// Get Configuration to be used at Logger //
42+
var splunkLoggerConfiguration = GetSplunkLoggerConfiguration(app);
43+
// //
44+
// Choose one or more of those loggers //
45+
// //
46+
loggerFactory.AddHECRawSplunkLogger(splunkLoggerConfiguration); //
4647
// //
4748
// //
4849
//loggerFactory.AddHECJsonSplunkLogger(splunkConfiguration); //

src/SampleWebAPI/appsettings.Development.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"LogLevel": {
55
"Default": "Debug",
66
"System": "Information",
7-
"Microsoft": "Information"
7+
"Microsoft": "Information",
8+
"Splunk": "Trace"
89
}
910
},
1011
"Splunk": {
@@ -19,8 +20,8 @@
1920
},
2021
"SocketConfiguration": {
2122
"HostName": "localhost",
22-
"Port": 4242,
23-
"Threshold": "Warning"
24-
}
23+
"Port": 4242
24+
},
25+
"Threshold": "Trace"
2526
}
2627
}

src/SampleWebAPI/appsettings.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
},
99
"Console": {
1010
"LogLevel": {
11-
"Default": "Warning"
11+
"Default": "Warning",
12+
"Splunk": "Trace"
1213
}
1314
},
1415
"Splunk": {
@@ -23,9 +24,9 @@
2324
},
2425
"SocketConfiguration": {
2526
"HostName": "localhost",
26-
"Port": 4242,
27-
"Threshold": "Warning"
28-
}
27+
"Port": 4242
28+
},
29+
"Threshold": "Trace"
2930
}
3031
}
3132
}

src/SplunkLogger/Loggers/BaseLogger.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace Splunk.Loggers
66
/// <summary>
77
/// Define a base logger class.
88
/// </summary>
9-
public abstract class BaseLogger
9+
public abstract class BaseLogger : ILogger
1010
{
1111
protected readonly ILoggerFormatter loggerFormatter;
1212

@@ -43,5 +43,7 @@ public IDisposable BeginScope<T>(T state)
4343
{
4444
return null;
4545
}
46+
47+
public abstract void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter);
4648
}
4749
}

src/SplunkLogger/Loggers/HECJsonLogger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public HECJsonLogger(string categoryName, LogLevel threshold, HttpClient httpCli
3232
/// <param name="state">Log object state.</param>
3333
/// <param name="exception">Log Exception.</param>
3434
/// <param name="formatter">Log text formatter function.</param>
35-
public void Log<T>(LogLevel logLevel, EventId eventId, T state, Exception exception, Func<T, Exception, string> formatter)
35+
public override void Log<T>(LogLevel logLevel, EventId eventId, T state, Exception exception, Func<T, Exception, string> formatter)
3636
{
3737
SplunkJSONEntry formatedMessage = null;
3838
if (loggerFormatter != null)

src/SplunkLogger/Loggers/HECRawLogger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public HECRawLogger(string categoryName, LogLevel threshold, HttpClient httpClie
3131
/// <param name="state">Log object state.</param>
3232
/// <param name="exception">Log Exception.</param>
3333
/// <param name="formatter">Log text formatter function.</param>
34-
public void Log<T>(LogLevel logLevel, EventId eventId, T state, Exception exception, Func<T, Exception, string> formatter)
34+
public override void Log<T>(LogLevel logLevel, EventId eventId, T state, Exception exception, Func<T, Exception, string> formatter)
3535
{
3636
string formatedMessage = string.Empty;
3737
if (loggerFormatter != null)

src/SplunkLogger/Loggers/TcpLogger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public TcpLogger(string categoryName, LogLevel threshold, TcpClient tcpClient, I
3434
/// <param name="state">Log object state.</param>
3535
/// <param name="exception">Log Exception.</param>
3636
/// <param name="formatter">Log text formatter function.</param>
37-
public void Log<T>(LogLevel logLevel, EventId eventId, T state, Exception exception, Func<T, Exception, string> formatter)
37+
public override void Log<T>(LogLevel logLevel, EventId eventId, T state, Exception exception, Func<T, Exception, string> formatter)
3838
{
3939
string formatedMessage = string.Empty;
4040
if (loggerFormatter != null)

0 commit comments

Comments
 (0)