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
The case above is using a **Splunk***HEC Raw*logger without any custom formatter as log provider.
47
+
As you can see, no matter what is your option you always must delivery a *SplunkLoggerConfiguration* when adding a ILogger to the logger factory. You can provide it via config or as hard code:
43
48
44
-
Now, in your controller you can log normally, for instance:
49
+
#### Get Configuration From Json File
45
50
46
-
```csharp
47
-
[Route("api/[controller]")]
48
-
publicclassValuesController : Controller
49
-
{
50
-
readonlyILoggerlogger;
51
+
You can provide the configuration from json file using .Net Core 2 configuration binding feature.
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**
* VTEXSplunkLoggerFormatter (*Custom `ILoggerFormatter` which creates VTEX's custom text to Splunk*)
83
-
84
+
If you intend to send data via **Http** you should set **HecConfiguration** section and if you choose to send data via socket you must set **SocketConfiguration** section.
84
85
85
-
## Usage
86
+
Now we need to configure SplunkLoggerConfiguration at dependency injection and indicate to use **Splunk** section from configuration file.
87
+
```csharp
88
+
/// <summary>
89
+
/// This method gets called by the runtime. Use this method to add services to the container.
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)
Again, 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
+
### Logging
118
146
147
+
Now that everything is configured and ILoggerFactory already have the desired ILogger instance added you can log your messages.
148
+
149
+
Here is a sample of how you can log messages, in this case I'm logging a `NotImplementedException` at [SampleWebAPI project](https://github.com/vtex/SplunkLogger/tree/master/src/SampleWebAPI)`ValuesController`.
150
+
151
+
```csharp
119
152
[Route("api/[controller]")]
120
153
publicclassValuesController : Controller
121
154
{
@@ -130,13 +163,16 @@ public class ValuesController : Controller
130
163
[HttpGet]
131
164
publicIEnumerable<string> Get()
132
165
{
133
-
logger.DefineVTEXLog(LogLevel.Critical,
134
-
"Values Controller",
135
-
"api/values",
136
-
string.Empty,
137
-
newNotImplementedException(),
138
-
newTuple<string, string>("method", "GET"));
166
+
logger.LogCritical(newEventId(-1, "Values Controller"), newNotImplementedException(), "Error on GET api/values route");
139
167
returnnewstring[] { "value1", "value2" };
140
168
}
141
169
}
142
170
```
171
+
172
+
## More Information
173
+
174
+
You can read more about the projects and it's details (like send http events as batch) at [Wiki page](https://github.com/vtex/SplunkLogger/wiki)
0 commit comments