Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elmah does not capture Post data of request #425

Closed
ankit57 opened this issue Nov 3, 2017 · 4 comments
Closed

Elmah does not capture Post data of request #425

ankit57 opened this issue Nov 3, 2017 · 4 comments
Labels

Comments

@ankit57
Copy link

ankit57 commented Nov 3, 2017

Elmah currently does not support logging and displaying the Post Data of the request. With all the new paradigm change of how we look at the web application now, Rest API are used pretty heavily. Capturing Post data will give more insight to the error and help debugging and reproducing the issue.

I have made the change and implemented it successfully in one of my application and wish that same be incorporated in base code so everyone can leverage the feature. I can push the code change if you make me collaborator else high level change is in Error.cs file to read the body from context.Request.InputStream. Displaying it on the log page is simple.

@atifaziz
Copy link
Member

atifaziz commented Nov 6, 2017

General post data is problematic to log. See my comment in issue #164 on why.

I can push the code change if you make me collaborator

You don't need permissions to share your work. You can do it via your own fork. You can also submit a PR here but it would be best if we discuss and agree on the design of your implementation before. As I said, it's problematic so I'm curious as to how you went about solving it.

@ankit57
Copy link
Author

ankit57 commented Nov 7, 2017

In Error.cs file, we can capture InputStream of Request and use StreamReader to get the string. Below is sample code

string jsonString = String.Empty;

            try
            {
                if (context.Request.InputStream != null)
                {
                    context.Request.InputStream.Position = 0;
                    using (StreamReader inputStream = new StreamReader(context.Request.InputStream))
                    {
                        jsonString = inputStream.ReadToEnd();
                    }
                }
            }
            catch (Exception)
            {
            }
            _postData = jsonString;

@atifaziz
Copy link
Member

atifaziz commented Nov 7, 2017

@ankit57 This assumes that InputStream is entirely committed to memory and can be rewound back (Position = 0). Unless you can point me to docs that state so, the assumption may not always hold true.

@atifaziz
Copy link
Member

Closing this as by-design.

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

No branches or pull requests

2 participants