GithubHelp home page GithubHelp logo

Comments (10)

TrapperHell avatar TrapperHell commented on August 20, 2024 1

This is to confirm that I can reproduce your issue (without the need for Task.Run), as such I will be re-opening this.

from serilog-sinks-slack.

TrapperHell avatar TrapperHell commented on August 20, 2024 1

I was pretty confident that this issue has already been resolved in the past - and in fact it was. Unfortunately a later commit undid the fix through an out-of-order disposal.

This should be resolved again in v2.2.0. Kindly confirm.

from serilog-sinks-slack.

geovanimartinez avatar geovanimartinez commented on August 20, 2024

I am running into the same issue, my work around is not efficient (using sleep thread) but has improved my delivery rate.

private void FlushAndExit(Exception exception, string message = "")
        {
            if (string.IsNullOrEmpty(message)) { message = "Unrecoverable Runtime Error, Application Will Exit"; }

            Log.Fatal(exception, message); // NOTE: Will post Fatal events to #devops slack channel 
            Log.Information("[{Name} - END...]", Assembly.GetEntryAssembly().GetName().Name);

            Log.CloseAndFlush();

            // Give ample time for the CloseAndFlush to finish...
            Thread.Sleep(new TimeSpan(0, 0, 0, 10));
            Environment.Exit(-1);
        }

from serilog-sinks-slack.

LaurensvandenBerg avatar LaurensvandenBerg commented on August 20, 2024

Same problem here, my program terminates rather quickly after i log an event to this sink. (i only send Fatal messages to slack as it runs on multiple machines).
When testing with the Thread.Sleep, i start to get the messages with a delay of about 1200-1250 ms, 1500 to be safe.
This however is very machine and instance specific and i'd figure there should be a different, more flexible way of checking if everything is sent before i dispose my program.

from serilog-sinks-slack.

homolibere avatar homolibere commented on August 20, 2024

v2.1.0 still not fixed

from serilog-sinks-slack.

TrapperHell avatar TrapperHell commented on August 20, 2024

@homolibere I'm going to need more information to work with this. This should have been fixed since v2.0.0, but there may be situations in which the app terminates before it is done flushing the content to the underlying sink, and thereby logging to slack.

from serilog-sinks-slack.

homolibere avatar homolibere commented on August 20, 2024

when i call Log.CloseAndFlush(); it does not wait till it flushes all messages and terminates application right away.
using Thread.Sleep is a only workaround, but it's a very dirty code.

from serilog-sinks-slack.

TrapperHell avatar TrapperHell commented on August 20, 2024

If I recall correctly that should be one of the more common scenarios which should work correctly, without the need for Thread.Sleep. I might need to take another look at it at some point next week. How are you using the logger in your application? Are you using DI at all, or working directly with the static Log ? Could you share a snippet of how you're configuring the logger in a succinct manner that reproduces the error?

from serilog-sinks-slack.

homolibere avatar homolibere commented on August 20, 2024
using Serilog;
using Serilog.Formatting.Json;
using Serilog.Sinks.Slack;

var configuration = new LoggerConfiguration().Enrich.FromLogContext();

configuration.WriteTo.Console(formatter: new JsonFormatter());
configuration.WriteTo.Slack("https://hooks.slack.com/services/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");

Log.Logger = configuration.CreateLogger();

Task task = Task.Run(async () => {
        for (int i = 0; i < 10; i++)
        {
            Log.Logger.Information(i.ToString());
            Task.Delay(500).Wait();
        }
    });

task.Wait();

Log.CloseAndFlush();

net6 console example. without delay 500 - it does not show any messages, with it at least firs 3-4

from serilog-sinks-slack.

homolibere avatar homolibere commented on August 20, 2024

Confirm, it is fixed now

from serilog-sinks-slack.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.