ecs-dotnet
ecs-dotnet copied to clipboard
Add log4net support
This PR adds support for log4net via ECS layout.
Changes:
- Added log4net ECS layout
- Added unit tests
- Updated site documentation
Please let me know if I missed anything.
Some open questions:
- [ ] Naming of the library:
Elastic.CommonSchema.Log4netorElastic.CommonSchema.log4net? Logging library is officially spelled aslog4net. - [ ] Do we want to provide the possibility to enrich logging event before logging? Similar to NLog layout implementations. Though this is only useful in case of programmatical configuration which I believe is a small minority of the use cases.
- [ ] Currently layout populates
service.versionfield, but this might be a wrong value. E.g., in case of IIS hosted applicationsGetEntryAssembly()return null so version of calling the calling assembly is used which might be different from the application version. Keep or drop? - [ ] Is example application needed?
:green_heart: Build Succeeded
the below badges are clickable and redirect to their specific view in the CI or DOCS
![]()
![]()
![]()
![]()
![]()
Expand to view the summary
Build stats
-
Start Time: 2022-09-06T07:06:04.528+0000
-
Duration: 27 min 18 sec
Test stats :test_tube:
| Test | Results |
|---|---|
| Failed | 0 |
| Passed | 152 |
| Skipped | 2 |
| Total | 154 |
:robot: GitHub comments
To re-run your PR in the CI, just comment with:
-
/test: Re-trigger the build. -
runelasticsearch-ci/docs: Re-trigger the docs validation. (use unformatted text in the comment!)
Jenkins run tests please
- Naming of the library: Elastic.CommonSchema.Log4net or Elastic.CommonSchema.log4net? Logging library is officially spelled as log4net.
I have no strong opinion but it seems common for the suffix to be Log4Net on nuget.org. I think my vote would go to adhere to regular namespacing rules.
- Do we want to provide the possibility to enrich logging event before logging? Similar to NLog layout implementations. Though this is only useful in case of programmatical configuration which I believe is a small minority of the use cases.
I'm fine leaving this out until we see strong evidence this is needed.
- Currently layout populates service.version field, but a wrong value might end up there. E.g., in case of IIS hosted applications GetEntryAssembly() returns null so version of the calling assembly is used which might be different from the application version. Keep or drop?
Drop, best to allign with what the Elastic Apm Agent does here:
https://github.com/elastic/apm-agent-dotnet/blob/305be0a9017ce9be50b4b269caa7404d14974cbb/src/Elastic.Apm/Config/AbstractConfigurationReader.cs#L853-L860
- Is example application needed?
No, the readme covers everything already IMO.
Drop, best to allign with what the Elastic Apm Agent does here: https://github.com/elastic/apm-agent-dotnet/blob/305be0a9017ce9be50b4b269caa7404d14974cbb/src/Elastic.Apm/Config/AbstractConfigurationReader.cs#L853-L860
Dropped for now. Imho best would be to implement later this approach for all three packages.
21:13:55 [xUnit.net 00:00:01.00] Elastic.CommonSchema.Log4net.Tests.MessageTests.ToEcs_AnyEvent_PopulatesHostField [FAIL]
21:13:55 Failed Elastic.CommonSchema.Log4net.Tests.MessageTests.ToEcs_AnyEvent_PopulatesHostField [36 ms]
21:13:55 Error Message:
21:13:55 Expected info.Host.Hostname to be
21:13:55 "APM-CI-IMMUTABL" with a length of 15, but
21:13:55 "apm-ci-immutable-windows-2019-1662404522828227605" has a length of 49, differs near "apm" (index 0).
It seems log4net lowercases hostname?
It seems log4net lowercases hostname?
Not really. It determines hostname using several sources in certain order. Whereas in the test I just compared the value against Environment.MachineName which returns hostname in upper case and truncated to 15 characters (I wasn't aware of such behavior). Fixed the test.
Merged, thanks for donating this implementation @andreycha :+1: