ChrisMissal/chromelogger

Only logs the first "log". Additional logs are ignored.

GFoley83 opened this issue · 7 comments

E.g. Calling

Logger.Error("Error 1");
Logger.Error("Error 2");

only shows Error 1 in the console. Regardless of whether logs occur in the same class or not.
Using version 0.1.1 and version 4.0.5 of Chrome plugin. Testing on localhost.

The problem right how is that two calls produces two headers:

X-ChromeLogger-Data:<data>
X-ChromeLogger-Data:<data>

So the logger needs to be "smarter" and collect the log calls, and output one header entry. This is definitely doable, but the application needs to trigger a flush or dispose. I was thinking something like this:

protected void Application_EndRequest(Object sender, EventArgs e)
{
    var logData = Logger.GetData();
    Context.Response.AddHeader(Logger.HeaderName, logData);
}

This is closer to the implementation in version 0.1.0, but I don't mind going back to that approach. Thoughts?

Or better yet:

protected void Application_EndRequest(Object sender, EventArgs e)
{
    Context.Response.Headers.Add(Logger.GetHeader());
}

I get the idea alright. Are GetHeader() and GetData() custom methods? As they're not available on the version I'm using.

They're just ideas I have right now, I haven't pushed out any code yet.

@GFoley83 I just pushed out a new version to NuGet: https://www.nuget.org/packages/ChromeLogger/

It does have a change you'll need to make. If you look at the readme, you'll see the code snippet. Let me know if you have any other troubles after the upgrade.

Thanks a lot. Tested and looks good.
The idea is that I wanted to hook ChromeLogger into my existing Log4Net implementation, to give me an additional way of viewing logs, without needing to log into the production environment. For example, smoke testing after a code release.

I have put a check around your method in Application_EndRequest to only add the header if the current user is authenticated, as I don't want any old Joe Soap seeing my potentially sensitive logs.

E.g.

protected void Application_EndRequest(object sender, EventArgs e) {
    var user = ((HttpApplication)sender).Context.User;
    var userIsLoggedIn = (user != null && user.Identity.IsAuthenticated);
    // Only add ChromeLogger headers if user is authenticated
    if(userIsLoggedIn) {
        Context.Response.Headers.Add(Logger.GetHeader());
    }
}

Happy to close this issue now.

Great news, thanks for the feedback!