Giter Site home page Giter Site logo

Comments (2)

tsimbalar avatar tsimbalar commented on May 27, 2024

not 100% sure if I understand correctly 🤔

  1. Why do you need to "dispose" of your CorrelationId in the OnUnload ? would "not disposing it" allow it to still exist at the moment where SerilogWeb logs the event ?
  2. wouldn't using or copying/adapting the current HttpRequestIdEnricher help ? note that it exposes static accessor in case you need access to the Id of the current request

public static bool TryGetCurrentHttpRequestId(out Guid requestId)

from classic.

mattheys avatar mattheys commented on May 27, 2024

Sorry I wasn't clear, I meant about disposing of the IDisposable property from PushProperty("CorrelationId",correlationId) I was using.

I've taken this approach instead since it's a simple single api that returns a document based on url properties and there is no state to manage, I just abandon the session before the page ends. I will take a look at the TryGetCurrentHttpRequestId and see if that helps as well.

        static Dictionary<Guid, IDisposable> logProperties = new Dictionary<Guid, IDisposable>();
        protected void Session_Start(object sender, EventArgs e)
        {
            var guid = Guid.NewGuid();
            Session["CorrelationId"] = guid;
            IDisposable logProperty = Serilog.Context.LogContext.PushProperty("CorrelationId", guid);
            Log.Verbose("Session {CorrelationId} started", guid);
            logProperties.Add(guid, logProperty);
        }
        protected void Session_End(object sender, EventArgs e)
        {
            Guid? guid = Session["CorrelationId"] as Guid?;

            if (!guid.HasValue)
            {
                Log.Verbose("Session with no CorrelationId ended, {CorrelationIdCount} in dictionary", logProperties.Count);
                return;
            }

            Log.Verbose("Session {CorrelationId} ended", guid);
            if (logProperties.TryGetValue(guid.Value, out var log))
            {
                log.Dispose();
                logProperties.Remove(guid.Value);
            }
        }

from classic.

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.