NickCraver / StackExchange.Exceptional

Error handler used for the Stack Exchange network
https://nickcraver.com/StackExchange.Exceptional/
Apache License 2.0
858 stars 170 forks source link

Not logging to mysql database #203

Closed kellielellie1 closed 3 years ago

kellielellie1 commented 3 years ago

I updated the StackExchange.Exceptional from 2.2.17 to 2.2.23 due to a reference error for mysql.

I have yet to be successful at logging an entry to the exceptions table in mysql. I have tried with both the default table name "Exceptions" and a custom table name "ExceptionLog" which includes adding an entry in appsettings.json for "TableName": "ExceptionLog".

The StackExchange.Exceptional error page shows on the UI, just no logging.

I am using ASP.NET Core 3.1 and have set up using the following walkthrough: Setup for ASP.NET Core

My Startup class has:

            services.AddExceptional(Configuration.GetSection("Exceptional"), settings =>
            {
                settings.UseExceptionalPageOnThrow = _currentEnvironment.IsDevelopment();
            });

and

app.UseExceptional();

My entry in appsettings.json is:

"Exceptional": {
    "Store": {
      "ApplicationName": "Helpinghand",
      "Type": "MySQL",
      "ConnectionString": "server=localhost;port=3306;user=root;password=[******];database=[name.name.com.au];",
      "TableName": "ExceptionLog"
    }
},

Im just throwing an exception on my HomeController Index action to test with:

        public async Task<IActionResult> Index()
        {
            throw new Exception("Oops.");
            return View();
         }
kellielellie1 commented 3 years ago

I got it working by adding "Allow User Variables=True" to the connection string

"Exceptional": { "Store": { "ApplicationName": "Helpinghand", "Type": "MySQL", "ConnectionString": "server=localhost;port=3306;user=root;password=[blah];database=[blah];Allow User Variables=True", "TableName": "ExceptionLog" } },

Hope that helps someone else