Giter Club home page Giter Club logo

Comments (4)

Sarojsigdel avatar Sarojsigdel commented on June 16, 2024 1

Create a derived class MsSqlErrorLogWithoutSensitiveInformation

 public class MsSqlErrorLogWithoutSensitiveInformation : SqlErrorLog
    {

        private List<String> sensitiveKeys = new List<string>() { "password", "pwd" };

        public MsSqlErrorLogWithoutSensitiveInformation(IOptions<ElmahOptions> option) : base(option)
        {
        }

        public MsSqlErrorLogWithoutSensitiveInformation(string connectionString, string schemaName, string tableName) : base(connectionString, schemaName, tableName)
        {
        }

        public override string Log(Error error)
        {
            var formKeys = error.Form.AllKeys;
            if (formKeys != null)
            {
                foreach (var key in formKeys)
                {

                    if (sensitiveKeys.Any(sk => key?.IndexOf(sk, StringComparison.OrdinalIgnoreCase) >= 0))
                    {
                        error.Form.Set(key, "******************");
                        if (error.Form.AllKeys.Contains("$request-body"))
                        {
                            error.Form.Remove("$request-body");
                        }
                    }
                }
            }

            return base.Log(error);

        }
    }

On Program.cs remove reference to SQLErrorLog and add reference to a derived class MsSqlErrorLogWithoutSensitiveInformation


builder.Services.AddElmah<MsSqlErrorLogWithoutSensitiveInformation>(options =>
{
    options.ConnectionString = builder.Configuration.GetConnectionString("ConnectionName");
    options.SqlServerDatabaseTableName = "ErrorLogs"; //Defaults to ELMAH_Error if not set
    options.Path = "errorlogs";
    options.OnPermissionCheck = context => context.User.Identity.IsAuthenticated;
  

});

That's it!!!

from elmahcore.

iliecs avatar iliecs commented on June 16, 2024

Any resolution on this? @Sarojsigdel did you find anything?

from elmahcore.

Sarojsigdel avatar Sarojsigdel commented on June 16, 2024

from elmahcore.

iliecs avatar iliecs commented on June 16, 2024

Are you able to share? Is it documented as a different issue? code snippet etc?

Thank you!

from elmahcore.

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.