Skip to content

Commit 19fae8c

Browse files
authored
Merge pull request #21 from vtex/documentation/create_project_usage_documentation
Create project README
2 parents 0f309f2 + 123be49 commit 19fae8c

File tree

1 file changed

+140
-1
lines changed

1 file changed

+140
-1
lines changed

README.md

Lines changed: 140 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,141 @@
11
# SplunkLogger
2-
C# .Net Core 2 Splunk ILogger Compatible Implementation
2+
This is a C# .Net Core 2 Splunk ILogger implementation developed at **VTEX** to send log to **Splunk**
3+
4+
| Package Name | Release |
5+
|--------------------------------|-----------------|
6+
| `SplunkLogger` | [![NuGet](https://img.shields.io/nuget/v/SplunkLogger.svg)](https://www.nuget.org/packages/SplunkLogger/) |
7+
8+
It was developed to be integrated to .Net Core 2 logging abstractions.
9+
10+
### Features
11+
12+
* ILoggerProviders (*SplunkHECJsonLoggerProvider*, *SplunkHECRawLoggerProvider*, *SplunkTcpLoggerProvider* and *SplunkUdpLoggerProvider*)
13+
* ILoggers (**HEC** (*Raw* and *Json*) and **Socket** (*TCP* and *UDP*)
14+
* Custom Configurations
15+
* Batch Manager class (Improve **Splunk** *HEC* performance sending data as batch)
16+
17+
## Usage
18+
19+
After add *SplunkLogger* nuget library
20+
```powershell
21+
PM> Install-Package SplunkLogger
22+
```
23+
24+
You should initialize a new *SplunkLoggerConfiguration* and the logger provider at **Configure** method at **Startup** class:
25+
26+
```csharp
27+
static readonly ILoggerFormatter formatter = null;
28+
29+
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
30+
{
31+
var splunkConfiguration = new SplunkLoggerConfiguration()
32+
{
33+
HecConfiguration = new HECConfiguration()
34+
{
35+
SplunkCollectorUrl = "https://localhost:8088/services/collector",
36+
Token = "753c5a9c-fb59-4da0-9064-947f99dc20ba"
37+
}
38+
};
39+
loggerFactory.AddHECRawSplunkLogger(splunkConfiguration, formatter);
40+
app.UseMvc();
41+
}
42+
```
43+
44+
In this case above we added a **Splunk** *HEC Raw* logger without any custom formmater as log provider.
45+
46+
Now in your controller you can log normally, for instance:
47+
48+
```csharp
49+
[Route("api/[controller]")]
50+
public class ValuesController : Controller
51+
{
52+
readonly ILogger logger;
53+
54+
public ValuesController(ILoggerFactory loggerFactory)
55+
{
56+
logger = loggerFactory.CreateLogger<ValuesController>();
57+
}
58+
59+
// GET api/values
60+
[HttpGet]
61+
public IEnumerable<string> Get()
62+
{
63+
logger.LogCritical(new EventId(-1, "Values Controller"), new NotImplementedException(), "Error on GET api/values route");
64+
return new string[] { "value1", "value2" };
65+
}
66+
}
67+
```
68+
69+
-------------------------------------------
70+
71+
# VTEXSplunkLogger
72+
For us at **VTEX** we need more customized log entries at Splunk and also we need easier ways to call for log registration during the code and for that we created this *VTEXSplunkLogger* library.
73+
74+
This project contains all **VTEX** extra classes designed to facilitate to log registration and also, all classes to customize .Net Core 2 log abstraction to a customized log entry at **Splunk**
75+
76+
| Package Name | Release |
77+
|--------------------------------|-----------------|
78+
| `VTEXSplunkLogger` | [![MyGet](https://img.shields.io/myget/vtexlab/v/VTEXSplunkLogger.svg)](https://www.myget.org/feed/vtexlab/package/nuget/VTEXSplunkLogger) |
79+
80+
### Features
81+
82+
* ILoggerExtensions (*Allow easy log creation*)
83+
* LoggerFactoryExtensions (*Simplify loggerFactory add provider method call*)
84+
* VTEXSplunkLoggerFormatter (*Custom `ILoggerFormatter` responsable for create VTEX custom text to Splunk*)
85+
86+
87+
## Usage
88+
89+
After add *VTEXSplunkLogger* nuget library
90+
```powershell
91+
PM> Install-Package VTEXSplunkLogger -Version 1.0.0 -Source https://www.myget.org/F/vtexlab/api/v3/index.json
92+
```
93+
94+
You should initialize a new *SplunkLoggerConfiguration* and the logger provider at **Configure** method at **Startup** class:
95+
96+
```csharp
97+
static readonly ILoggerFormatter formatter = new VTEXSplunkLoggerFormatter();
98+
99+
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
100+
{
101+
var splunkConfiguration = new SplunkLoggerConfiguration()
102+
{
103+
HecConfiguration = new HECConfiguration()
104+
{
105+
SplunkCollectorUrl = "https://localhost:8088/services/collector",
106+
Token = "753c5a9c-fb59-4da0-9064-947f99dc20ba"
107+
}
108+
};
109+
loggerFactory.AddHECRawSplunkLogger(splunkConfiguration, formatter);
110+
app.UseMvc();
111+
}
112+
```
113+
114+
```csharp
115+
using Vtex;
116+
//other usings ..
117+
118+
[Route("api/[controller]")]
119+
public class ValuesController : Controller
120+
{
121+
readonly ILogger logger;
122+
123+
public ValuesController(ILoggerFactory loggerFactory)
124+
{
125+
logger = loggerFactory.CreateLogger<ValuesController>();
126+
}
127+
128+
// GET api/values
129+
[HttpGet]
130+
public IEnumerable<string> Get()
131+
{
132+
logger.DefineVTEXLog(LogLevel.Critical,
133+
"Values Controller",
134+
"api/values",
135+
string.Empty,
136+
new NotImplementedException(),
137+
new Tuple<string, string>("method", "GET"));
138+
return new string[] { "value1", "value2" };
139+
}
140+
}
141+
```

0 commit comments

Comments
 (0)