fix logger
continuous-integration/drone/push Build is passing Details

pagination
Tony Fages 1 year ago
parent d620088c63
commit d4eef3da9a

@ -15,3 +15,20 @@ info: 03/15/2024 16:59:30.063 RelationalEventId.CommandExecuted[20101] (Microsof
Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30'] Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT "a"."Id", "a"."Author", "a"."DatePublished", "a"."Description", "a"."LectureTime", "a"."Title" SELECT "a"."Id", "a"."Author", "a"."DatePublished", "a"."Description", "a"."LectureTime", "a"."Title"
FROM "ArticleSet" AS "a" FROM "ArticleSet" AS "a"
info: 03/15/2024 17:08:29.557 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command)
Executed DbCommand (6ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT COUNT(*) FROM "sqlite_master" WHERE "name" = '__EFMigrationsHistory' AND "type" = 'table';
info: 03/15/2024 17:08:29.561 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command)
Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT COUNT(*) FROM "sqlite_master" WHERE "name" = '__EFMigrationsHistory' AND "type" = 'table';
info: 03/15/2024 17:08:29.567 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command)
Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT "MigrationId", "ProductVersion"
FROM "__EFMigrationsHistory"
ORDER BY "MigrationId";
info: 03/15/2024 17:08:29.575 RelationalEventId.MigrationsNotApplied[20405] (Microsoft.EntityFrameworkCore.Migrations)
No migrations were applied. The database is already up to date.
info: 03/15/2024 17:08:33.305 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command)
Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT "a"."Id", "a"."Author", "a"."DatePublished", "a"."Description", "a"."LectureTime", "a"."Title"
FROM "ArticleSet" AS "a"

@ -6,27 +6,32 @@ namespace DbContextLib;
public class LibraryContext : DbContext public class LibraryContext : DbContext
{ {
private static readonly StreamWriter LogFile = new StreamWriter("log.txt");
public LibraryContext() public LibraryContext()
: base() : base()
{ } {
}
public LibraryContext(DbContextOptions<LibraryContext> options) public LibraryContext(DbContextOptions<LibraryContext> options)
: base(options) : base(options)
{ } {
}
public DbSet<ArticleEntity> ArticleSet { get; set; } public DbSet<ArticleEntity> ArticleSet { get; set; }
public DbSet<UserEntity> UserSet { get; set; } public DbSet<UserEntity> UserSet { get; set; }
public DbSet<FormEntity> FormSet { get; set; } public DbSet<FormEntity> FormSet { get; set; }
public DbSet<ArticleUserEntity> ArticleUserSet { get; set; } public DbSet<ArticleUserEntity> ArticleUserSet { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{ {
optionsBuilder.LogTo(message => LogFile.WriteLine(message), LogLevel.Information); optionsBuilder.LogTo(message =>
{
using var logFile = new StreamWriter("log.txt", append: true);
logFile.WriteLine(message);
}, LogLevel.Information);
if (!optionsBuilder.IsConfigured) if (!optionsBuilder.IsConfigured)
{ {
optionsBuilder.UseSqlite($"Data Source=Entity_FrameWork.Article.db"); optionsBuilder.UseSqlite($"Data Source=Entity_FrameWork.Article.db");
@ -41,12 +46,12 @@ public class LibraryContext : DbContext
.HasMany(a => a.Users) .HasMany(a => a.Users)
.WithMany(a => a.Articles) .WithMany(a => a.Articles)
.UsingEntity<ArticleUserEntity>(); .UsingEntity<ArticleUserEntity>();
modelBuilder.Entity<UserEntity>() modelBuilder.Entity<UserEntity>()
.HasMany(u => u.Forms) .HasMany(u => u.Forms)
.WithOne(f => f.User) .WithOne(f => f.User)
.HasForeignKey(f => f.UserEntityPseudo); .HasForeignKey(f => f.UserEntityPseudo);
modelBuilder.Entity<FormEntity>() modelBuilder.Entity<FormEntity>()
.HasOne(f => f.User) .HasOne(f => f.User)
.WithMany(u => u.Forms) .WithMany(u => u.Forms)
@ -80,7 +85,7 @@ public class LibraryContext : DbContext
Description = "M&M's new recipe is out and it's the best chocolate ever", Description = "M&M's new recipe is out and it's the best chocolate ever",
DatePublished = "2022-02-06", DatePublished = "2022-02-06",
LectureTime = 1, LectureTime = 1,
Author = "M&M's Red" Author = "M&M's Red"
} }
); );
@ -107,7 +112,7 @@ public class LibraryContext : DbContext
Nom = "Sillard", Prenom = "Noa", Pseudo = "NoaSil", Mail = "", Mdp = "1234", Role = "Admin" Nom = "Sillard", Prenom = "Noa", Pseudo = "NoaSil", Mail = "", Mdp = "1234", Role = "Admin"
} }
); );
modelBuilder.Entity<ArticleUserEntity>().HasData( modelBuilder.Entity<ArticleUserEntity>().HasData(
new ArticleUserEntity new ArticleUserEntity
{ {
@ -135,11 +140,11 @@ public class LibraryContext : DbContext
UserEntityPseudo = "TomS" UserEntityPseudo = "TomS"
} }
); );
modelBuilder.Entity<FormEntity>().HasData( modelBuilder.Entity<FormEntity>().HasData(
new FormEntity new FormEntity
{ {
Id = 1, Id = 1,
DatePublication = "Form 1 Description", DatePublication = "Form 1 Description",
Link = "hhtp://form1.com", Link = "hhtp://form1.com",
UserEntityPseudo = "Sha" UserEntityPseudo = "Sha"
@ -161,16 +166,4 @@ public class LibraryContext : DbContext
); );
*/ */
} }
public override void Dispose()
{
base.Dispose();
LogFile.Dispose();
}
public override async ValueTask DisposeAsync()
{
await base.DisposeAsync();
await LogFile.DisposeAsync();
}
} }
Loading…
Cancel
Save