MT.Extensions.Logging.MsSql
2.2.0
See the version list below for details.
dotnet add package MT.Extensions.Logging.MsSql --version 2.2.0
NuGet\Install-Package MT.Extensions.Logging.MsSql -Version 2.2.0
<PackageReference Include="MT.Extensions.Logging.MsSql" Version="2.2.0" />
paket add MT.Extensions.Logging.MsSql --version 2.2.0
#r "nuget: MT.Extensions.Logging.MsSql, 2.2.0"
// Install MT.Extensions.Logging.MsSql as a Cake Addin #addin nuget:?package=MT.Extensions.Logging.MsSql&version=2.2.0 // Install MT.Extensions.Logging.MsSql as a Cake Tool #tool nuget:?package=MT.Extensions.Logging.MsSql&version=2.2.0
MT.Extensions.Logging.MsSql
An .net Core Logger Extension that logs to MsSql server using stored procedure. (ELMAH for Asp.Net Core)
An Extension of ILogger to log Data into MsSql DB, This is an alternative for ELMAH in asp.net mvc. currently there is no page to view errors, or error details inside, but anyone can help will be appreciated.
The Default LogLevel for this Extension is Error, (if not specified).
How to Install.
1- Before using this tool, Create a Database, and add Connection string into appsetting.json like below.
{
"ConnectionStrings": {
"LoggerConnection" : "Server=(localdb)\\MSSQLLocalDB;Database=Logs;Trusted_Connection=True;MultipleActiveResultSets=true"
},
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning"
}
}
}
2- Execute CreateScript.sql file in database
Update Script:
Not: If you are updating from version 2.0.1 or below, please run update script below:
Create Script
Not if this is first time you are installing this nuget package, run below script to create tables and sp.
3- in Asp.net Core Web Application in startup.cs add following codes:
3-1-
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
// Add This Line To access HttpContext from within the MsSqlLogger to get the user name, trace Identifier that gets error also for returning back logId inside httpContext.
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddMvc();
}
3-2-
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory,
IHttpContextAccessor httpContextAccessor)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
// Add This To Log to MsSql Db
loggerFactory.AddMsSql(Configuration.GetConnectionString("LoggerConnection"), httpContextAccessor, "SampleApplication");
// Also you can add as Provider as below:
//loggerFactory.AddProvider(new MsSqlLoggerProvider((_, LogLevel) => LogLevel >= LogLevel.Trace,
// Configuration.GetConnectionString("LoggerConnection"), null,"SampleApplication"));
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
Using in Asp.net Core Web Application Targetting .NetFramework
To Use in Asp.Net Web Application targetting .NetFramework you should also add following nuget packages manually to your project.
System.Security.Claims (4.3) from <a href='https://www.nuget.org/packages/System.Security.Claims/'>NUGET</a>
System.Diagnostics.StackTrace (4.3) from <a href='https://www.nuget.org/packages/System.Diagnostics.StackTrace'>NUGET</a>
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.AspNetCore.Http.Abstractions (>= 2.0.1)
- Microsoft.AspNetCore.WebUtilities (>= 2.0.1)
- Microsoft.Extensions.Logging.Abstractions (>= 2.0.0)
- Newtonsoft.Json (>= 10.0.3)
- System.Data.SqlClient (>= 4.4.2)
- System.Diagnostics.StackTrace (>= 4.3.0)
- System.Security.Claims (>= 4.3.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Added new RequestId column, to save TraceIdentifer of current request.
Used HttpContext.Items["ExceptionLogId"] to return currently saved exception logs. Not: this value will be set for LogError only.
Added an update script to update from previous database scheme to current.