Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/karenpayneoregon/ef-core5-logging

Basic EF Core logging examples
https://github.com/karenpayneoregon/ef-core5-logging

csharp entity-framework-core sql-server visualstudio2019

Last synced: 8 days ago
JSON representation

Basic EF Core logging examples

Awesome Lists containing this project

README

        

# EF Core logging in .NET Core 5 (C#)

Provides basic Entity Framework Core logging code samples.

---

Make sure to read [ConfigurationHelper](https://github.com/karenpayneoregon/ef-core5-logging/blob/master/ConfigurationHelper/Documentation/ConfigurationHelper.md) which descibes various settings for `connection string` and `logging`.

:heavy_check_mark: Read EF Core connection string from appsettings.json

:heavy_check_mark: Configuring EF Core logging from appsettings.json

**Options** for logging

```csharp
public enum LoggingDestination
{
///
/// Log to Output window
///
DebugWindow,
///
/// Log to file
///
LogFile,
///
/// No logging
///
None
}
```

**Usage**: reads [appsettings.json](https://github.com/karenpayneoregon/ef-core5-logging/blob/master/LogToFile/appsettings.json)

```csharp
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
switch (Helper.LoggingDistination())
{
case LoggingDestination.DebugWindow:
LogQueryInfoToDebugOutputWindow(optionsBuilder);
break;
case LoggingDestination.LogFile:
LogQueryInfoToFile(optionsBuilder);
break;
case LoggingDestination.None:
NoLogging(optionsBuilder);
break;
default: throw new ArgumentOutOfRangeException();
}
}
}
```

![img](assets/efcore.png) ![image](assets/Versions.png)
![img](assets/csharpSmall.png)

# NuGet packages

|Id| Versions |
| :--- | :--- |
|Microsoft.Extensions.Configuration.FileExtensions| {5.0.0} |
|Newtonsoft.Json| {12.0.3} |
|Microsoft.Extensions.Configuration.Binder| {5.0.0} |
|Microsoft.Extensions.Configuration.Json| {5.0.0} |
|Microsoft.Extensions.Configuration| {5.0.0} |

# See also

- Microsoft TechNet:
- [.NET Core desktop application configurations (C#)](https://social.technet.microsoft.com/wiki/contents/articles/54173.net-core-desktop-application-configurations-c.aspx)
- [Entity Framework/Entity Framework Core dynamic connection strings (C#)](https://social.technet.microsoft.com/wiki/contents/articles/54079.entity-frameworkentity-framework-core-dynamic-connection-strings-c.aspx)
- [Entity Framework Core/Windows Forms tips and tricks](https://social.technet.microsoft.com/wiki/contents/articles/53635.entity-framework-corewindows-forms-tips-and-tricks.aspx)
- Microsoft docs
- [Entity Framework Core](https://docs.microsoft.com/en-us/ef/core/)
- [Porting from EF6 to EF Core](https://docs.microsoft.com/en-us/ef/efcore-and-ef6/porting/)
- Tools
- [EF Core Power Tools](https://marketplace.visualstudio.com/items?itemName=ErikEJ.EFCorePowerTools)

---

![img](assets/kpmvp1.png)