Skip to content
This repository has been archived by the owner on Jun 1, 2024. It is now read-only.

No exception data in elastic for logger.Error(ex, "... #447

Open
iomdesign opened this issue Jun 1, 2022 · 1 comment
Open

No exception data in elastic for logger.Error(ex, "... #447

iomdesign opened this issue Jun 1, 2022 · 1 comment

Comments

@iomdesign
Copy link

A few questions before you begin:

Is this an issue related to the Serilog core project or one of the sinks or
community projects.
This issue is intended for Serilog Elasticsearch Sink issues.

Does this issue relate to a new feature or an existing bug?

  • [ x ] Bug

What version of Serilog.Sinks.Elasticsearch is affected? Please list the related NuGet package.
8.4.1

What is the target framework and operating system? See target frameworks & net standard matrix.

  • [ x ] 4.6.x

Please describe the current behavior?
In the following scenario, the log in elastic has the log message but no exception whereas the same log written to file contains the full exception details.

try
{
...
}
catch (Exception ex)
{
    logger.Error(ex, "Error doing some stuff: {xyz}", xyz);
    ...do some handling stuff
}

I have noticed in a different project of the same solution (same versions of serilog packages and target framework) that the following scenario resulted in the log in elastic being as expected...

catch (Exception ex)
{
    var exMessage = ex.Message;
    logger.Error(ex, " Some error - [exMessage: {exMessage}]", exMessage);
    throw;
}

and the log entry contained

    "exceptions": [
      {
        "Depth": 0,
        "ClassName": "System.ServiceModel.FaultException",
        "Message": "Server was unable to process request. ---> Exception has been thrown by the target of an
... 

Please describe the expected behavior?
Log in elastic should contain exception

If the current behavior is a bug, please provide the steps to reproduce the issue and if possible a minimal demo of the problem
This is our logging config

        public static void StartLogger()
        {
            SetEnvironmentName();
            //Change TLS version to support elasticsearch
            System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;

            Log.Logger = new LoggerConfiguration()
                .WriteTo.File(FilePattern, rollingInterval: RollingInterval.Day)
                .WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri(ElasticSearchUrl))
                {
                    AutoRegisterTemplate = false,
                    //AutoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv7,
                    IndexFormat = string.Format("{0}{1}", ElasticSearchIndex, "-{0:yyyy.MM.dd}"),
                    ModifyConnectionSettings = x => x.BasicAuthentication(ElasticSearchUser, ElasticSearchPassword),
                    TypeName = null
                })
                .MinimumLevel.Is(SerilogMinimumLevel)
                .Enrich.WithProperty("Application", AppName)
                .Enrich.WithProperty("RequestId", Guid.NewGuid())
                .Enrich.WithEnvironmentName()
                .Enrich.WithMachineName()
                .Enrich.FromLogContext()
                .CreateLogger();

            Log.Information("App up");
        }

@AlexGoris-KasparSolutions

Take a look at this issue: elastic/ecs-dotnet#158

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants