Serilog.Sinks.Logz.Io icon indicating copy to clipboard operation
Serilog.Sinks.Logz.Io copied to clipboard

Get logzio-index-failure when using scoped variables

Open advapiIT opened this issue 1 year ago • 2 comments

Hello, I'm using Serilog + Serilog.Sinks.Logz.io to send event to Logzio (europe). I've been contacted by the support since they told me that I've tons of log message that cannot be indexed since I used the Scope.

In particular consider this case image

They wrote me :" Im still checking, but it looks to be from the field "properties.Scope_list". The field is getting sent as an array and causing index failures"

My code is thefollowing, since I have those properties that needs to be attached to all the nested logs starting from the using:

            foreach (var productInventoryIdByExternalProductId in filtered)
            {
                _logger.BeginScope(new Dictionary<string, string>()
                {
                    { "ProductInventoryId", productInventoryIdByExternalProductId.Key.ToString() },
                    {"ExternalProductId",  productInventoryIdByExternalProductId.Value}
                });

                _logger.LogInformation($"Started processing ProductInventoryId: {productInventoryIdByExternalProductId.Key} .[{count}/{total}]");

What am I doing wrong? Thanks

advapiIT avatar Nov 07 '23 16:11 advapiIT

To be honest - for me all these things looks legit, as ElasticSearch/OpenSearch supports arrays without any issues, see: https://www.elastic.co/guide/en/elasticsearch/reference/current/array.html However - maybe the issue is that you have these arrays create in multiple places with the same name, but inside you have different properties?

mantasaudickas avatar Nov 08 '23 06:11 mantasaudickas

By looking more closely.. it seems like with a single log message you need only one pair of ProductInventoryId and ExternalProductId, is that right? Because now.. since you are not disposing scope - every log line gets more and more these entries. So one way would be (see added using):

foreach (var productInventoryIdByExternalProductId in filtered)
            {
                using var scope = _logger.BeginScope(new Dictionary<string, string>()
                {
                    { "ProductInventoryId", productInventoryIdByExternalProductId.Key.ToString() },
                    {"ExternalProductId",  productInventoryIdByExternalProductId.Value}
                });

                _logger.LogInformation($"Started processing ProductInventoryId: {productInventoryIdByExternalProductId.Key} .[{count}/{total}]");

Another option:

foreach (var productInventoryIdByExternalProductId in filtered)
{
     _logger.LogInformation("Started processing ProductInventoryId = {ProductInventoryId}. ExternalProductId = {ExternalProductId}. [{Count}/{Total}]", productInventoryIdByExternalProductId.Key, productInventoryIdByExternalProductId.Value, count, total);

mantasaudickas avatar Nov 08 '23 08:11 mantasaudickas