Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Exceptions aren't logged to target when using ElasticCommonSchema #139

Closed
fabianrieder opened this issue Mar 31, 2021 · 8 comments
Closed
Labels
bug Something isn't working

Comments

@fabianrieder
Copy link

fabianrieder commented Mar 31, 2021

ECS integration/library project(s) (e.g. Elastic.CommonSchema.Serilog): Elastic.CommonSchema.NLog + Elastic.Apm.NLog

ECS schema version (e.g. 1.4.0):

ECS .NET assembly version (e.g. 1.4.2): 1.5.1

Elasticsearch version (if applicable):

.NET framework / OS: .NET-Framework 4.7.2, Win 10

Description of the problem, including expected versus actual behavior:
If I log a Warning with an exception, the logentry isn't written to the file when i use the EcsLayout

Steps to reproduce:

  1. add Extensions to nlog.config (also Install the according NuGet-Packages):
 	<extensions>
		<add assembly="NLog.Targets.ElasticSearch"/>
		<add assembly="Elastic.Apm.NLog"/>
		<add assembly="Elastic.CommonSchema.NLog"/>	
	</extensions>
  1. Add a target that uses the EcsLayout
 <target xsi:type="File" name="logEcs" fileName="./logs/ecs.json">
	  <layout xsi:type="EcsLayout"/>
</target>
  1. try to write a log-entry with an exception:
        private static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();

        static void Main(string[] args)
        {
            Logger.Info("Hello world");
            Logger.Warn(new KeyNotFoundException("Key"), "Error!!!");
        }

The Output-File only has 1 logmessage written, the one with the exception is missing_

{"@timestamp":"2021-03-31T13:53:32.6042159+02:00","log.level":"Info","message":"Hello world","ecs":{"version":"1.5.0"},"event":{"severity":6,"timezone":"Mitteleurop\u00E4ische Zeit","created":"2021-03-31T13:53:32.6042159+02:00"},"host":{"name":"*********","ip":["******"]},"log":{"logger":"Logging.Elastic.Demo.NLogTest.Program","original":"Hello world"},"process":{"thread":{"id":*******},"pid":*****,"name":"Logging.Elastic.Demo.NLogTest","executable":"C:\\Source\\Logging.Elastic.Demo\\Logging.Elastic.Demo.NLogTest\\bin\\Debug\\Logging.Elastic.Demo.NLogTest.exe","title":"C:\\Source\\Logging.Elastic.Demo\\Logging.Elastic.Demo.NLogTest\\bin\\Debug\\Fronius.Logging.Elastic.Demo.NLogTest.exe"},"server":{"user":{"name":"********"}}}

The NLOG-Logfile shows the following Error/Exception:

2021-03-31 13:53:32.8682 Error File Target[logEcs]: Error has been raised. Exception: System.NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
   bei Elastic.CommonSchema.NLog.EcsLayout.CatchError(Exception error) in /home/mpdreamz/projects/elastic/ecs-dotnet/src/Elastic.CommonSchema.NLog/EcsLayout.cs:Zeile 191.
   bei Elastic.CommonSchema.NLog.EcsLayout.GetError(Exception exception) in /home/mpdreamz/projects/elastic/ecs-dotnet/src/Elastic.CommonSchema.NLog/EcsLayout.cs:Zeile 168.
   bei Elastic.CommonSchema.NLog.EcsLayout.RenderFormattedMessage(LogEventInfo logEvent, StringBuilder target) in /home/mpdreamz/projects/elastic/ecs-dotnet/src/Elastic.CommonSchema.NLog/EcsLayout.cs:Zeile 122.
   bei NLog.Layouts.Layout.RenderAppendBuilder(LogEventInfo logEvent, StringBuilder target, Boolean cacheLayoutResult)
   bei NLog.Targets.FileTarget.RenderFormattedMessage(LogEventInfo logEvent, StringBuilder target)
   bei NLog.Targets.FileTarget.RenderFormattedMessageToStream(LogEventInfo logEvent, StringBuilder formatBuilder, Char[] transformBuffer, MemoryStream streamTarget)
   bei NLog.Targets.FileTarget.Write(LogEventInfo logEvent)
   bei NLog.Targets.Target.Write(AsyncLogEventInfo logEvent)
@fabianrieder fabianrieder added the bug Something isn't working label Mar 31, 2021
@fabianrieder
Copy link
Author

fabianrieder commented Apr 26, 2021

Same behaviour with Serilog when using EcsTextFormatter (as described in this documentation https://www.elastic.co/guide/en/apm/agent/dotnet/master/serilog.html#serilog

@Leftyx
Copy link

Leftyx commented Apr 30, 2021

It seems the issue has been fixed as I have tested the source code and it works fine.
Any plans to push to nuget ?

@russcam
Copy link
Contributor

russcam commented May 27, 2021

@Leftyx @fabianrieder I'm looking at pushing out a new release

@russcam
Copy link
Contributor

russcam commented Jun 1, 2021

@Leftyx 1.5.3 has been released to nuget. Are you able to upgrade and report if it solves the issue?

@Leftyx
Copy link

Leftyx commented Jun 1, 2021

@russcam I've updated the package to 1.5.3 and it works like charm. Thank

@russcam
Copy link
Contributor

russcam commented Jun 1, 2021

Great to hear, @Leftyx! I'll close this issue now

@russcam russcam closed this as completed Jun 1, 2021
@AlexGoris-KasparSolutions

@fabianrieder did you resolve your issue with Serilog with 1.5.3 of this package? I keep having the same problem, if I remove the CustomFormatter = EcsTextFormatter() line my logs do have exceptions in them in elastic (but not all the other ECS fields), and when I add the exceptions are lost...

@fabianrieder
Copy link
Author

@fabianrieder did you resolve your issue with Serilog with 1.5.3 of this package? I keep having the same problem, if I remove the CustomFormatter = EcsTextFormatter() line my logs do have exceptions in them in elastic (but not all the other ECS fields), and when I add the exceptions are lost...

Unfortunately not. i still have the same issue that exceptions aren't sent to ElasticSearch when usingn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants