You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can provide the configuration from json file. In this case I will be using *appsettings.json* as source and loading it using .Net Core 2 configuration binding feature.
56
53
57
-
// GET api/values
58
-
[HttpGet]
59
-
publicIEnumerable<string> Get()
60
-
{
61
-
logger.LogCritical(newEventId(-1, "Values Controller"), newNotImplementedException(), "Error on GET api/values route");
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. For that, we created this *VTEXSplunkLogger* library.
71
-
72
-
This project contains all **VTEX** extra classes designed to ease logging. All classes changes .Net Core 2 log abstraction to a customized log entry at **Splunk**
If you intend to use send data via **Http** you should set **HecConfiguration** section and if you choose to send data via socket you must set **SocketConfiguration** section.
Now that `SplunkLoggerConfiguration` class is configured we can retrieve it by requesting `IOptions<SplunkLoggerConfiguration>` at dependency injection service, like:
99
+
```csharp
100
+
/// <summary>
101
+
/// Demonstrate how can you provide configuration to your splunk logger addapter(s)
If you intend to use send data via **Http** you should set **HecConfiguration** property and if you choose to send data via socket you must set **SocketConfiguration** property.
144
+
145
+
### Sample Logging
146
+
147
+
At controller you must receive `ILoggerFactory loggerFactory` and extract `ILogger`from it and use this `ILogger` instance to log any desired event, as sample below:
118
148
149
+
```csharp
119
150
[Route("api/[controller]")]
120
151
publicclassValuesController : Controller
121
152
{
@@ -130,13 +161,12 @@ public class ValuesController : Controller
130
161
[HttpGet]
131
162
publicIEnumerable<string> Get()
132
163
{
133
-
logger.DefineVTEXLog(LogLevel.Critical,
134
-
"Values Controller",
135
-
"api/values",
136
-
string.Empty,
137
-
newNotImplementedException(),
138
-
newTuple<string, string>("method", "GET"));
164
+
logger.LogCritical(newEventId(-1, "Values Controller"), newNotImplementedException(), "Error on GET api/values route");
0 commit comments