Testing serilog
This commit is contained in:
BIN
Least_Sign_To_Most_Sign.jpg
Normal file
BIN
Least_Sign_To_Most_Sign.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 50 KiB |
@ -29,7 +29,7 @@ public class AccountRecordRepository : IAccountRecordRepository
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError($"Error occured in AddAccountRecord :{e.Message}");
|
||||
_logger.LogError("Error occured in AddAccountRecord :-->{iMessage}", e.Message);
|
||||
}
|
||||
return false;
|
||||
|
||||
@ -45,7 +45,7 @@ public class AccountRecordRepository : IAccountRecordRepository
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError($"Error occured in DeleteAccountRecord :{e.Message}");
|
||||
_logger.LogError("Error occured in DeleteAccountRecord :-->{iMessage}", e.Message);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -129,7 +129,7 @@ public class ReadingIn : IReadingIn
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError($"MassUppdatering misslyckat: {ex.Message}");
|
||||
_logger.LogError("MassUppdatering misslyckat: -->{iMessage}", ex.Message);
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
BIN
WinFormDi/Local.db-shm
Normal file
BIN
WinFormDi/Local.db-shm
Normal file
Binary file not shown.
0
WinFormDi/Local.db-wal
Normal file
0
WinFormDi/Local.db-wal
Normal file
@ -1,8 +1,11 @@
|
||||
using DIDemoLib;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using WinFormDiApp.DAL;
|
||||
using WinFormDiApp.DAL.Data;
|
||||
using Serilog;
|
||||
using Serilog.Formatting.Json;
|
||||
|
||||
namespace WinFormDiApp
|
||||
{
|
||||
@ -14,12 +17,20 @@ namespace WinFormDiApp
|
||||
[STAThread]
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.WriteTo.Console()
|
||||
.WriteTo.File(@"D:\logs\winformApp.txt",restrictedToMinimumLevel:Serilog.Events.LogEventLevel.Information,
|
||||
rollingInterval: RollingInterval.Day)
|
||||
.CreateLogger();
|
||||
|
||||
var host = ContainerConfig.Configure(CreateHostBuilder(args));
|
||||
|
||||
using var scope = host.Services.CreateScope();
|
||||
|
||||
try
|
||||
{
|
||||
Log.Information("Starting of service..");
|
||||
|
||||
var services = scope.ServiceProvider;
|
||||
|
||||
var context = services.GetRequiredService<ApplicationDbContext>();
|
||||
@ -34,13 +45,26 @@ namespace WinFormDiApp
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"An error has occured: {ex.Message}");
|
||||
Log.Fatal(ex, "Exception in application");
|
||||
}
|
||||
finally
|
||||
{
|
||||
Log.Information("Exiting service..");
|
||||
Log.CloseAndFlush();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
||||
Host.CreateDefaultBuilder(args);
|
||||
Host.CreateDefaultBuilder(args)
|
||||
.UseSerilog()
|
||||
.ConfigureLogging((context, logging) =>
|
||||
{
|
||||
logging.ClearProviders();
|
||||
logging.AddConfiguration(context.Configuration.GetSection("Logging"));
|
||||
logging.AddConsole();
|
||||
logging.AddDebug();
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
@ -17,6 +17,10 @@
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
||||
<PackageReference Include="Serilog" Version="3.0.1" />
|
||||
<PackageReference Include="Serilog.Extensions.Hosting" Version="7.0.0" />
|
||||
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@ -1,16 +1,26 @@
|
||||
{
|
||||
"EPPlus": {
|
||||
"ExcelPackage": {
|
||||
"LicenseContext": "Noncommercial" //The license context used
|
||||
}
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"ConnectionStrings": {
|
||||
"DatabaseConnection": "Data Source=.\\Local.db"
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Warning"
|
||||
}
|
||||
},
|
||||
"Console": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft*": "Warning"
|
||||
}
|
||||
},
|
||||
"Debug": {
|
||||
"LogLevel": {
|
||||
"Default": "Warning",
|
||||
"Microsoft*": "Warning"
|
||||
}
|
||||
},
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.Hosting.Lifetime": "Warning",
|
||||
"Microsoft*": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
|
||||
@ -24,6 +24,7 @@ namespace WinFormDiApp
|
||||
|
||||
private void frmPayments_Load(object sender, EventArgs e)
|
||||
{
|
||||
lvPayments.Items.Clear();
|
||||
var payments = _accountRecordRepository.GetAllAccounts();
|
||||
foreach (var account in payments)
|
||||
{
|
||||
|
||||
6
WinFormDi/frmReadPayments.Designer.cs
generated
6
WinFormDi/frmReadPayments.Designer.cs
generated
@ -92,7 +92,7 @@
|
||||
//
|
||||
// btnClose
|
||||
//
|
||||
btnClose.Location = new Point(758, 418);
|
||||
btnClose.Location = new Point(758, 506);
|
||||
btnClose.Name = "btnClose";
|
||||
btnClose.Size = new Size(75, 23);
|
||||
btnClose.TabIndex = 1;
|
||||
@ -107,7 +107,7 @@
|
||||
lvPayouts.Columns.AddRange(new ColumnHeader[] { columnHeader1, columnHeader2, columnHeader3, columnHeader4, columnHeader5, columnHeader6 });
|
||||
lvPayouts.Location = new Point(28, 107);
|
||||
lvPayouts.Name = "lvPayouts";
|
||||
lvPayouts.Size = new Size(805, 286);
|
||||
lvPayouts.Size = new Size(805, 393);
|
||||
lvPayouts.TabIndex = 2;
|
||||
lvPayouts.UseCompatibleStateImageBehavior = false;
|
||||
lvPayouts.View = View.Details;
|
||||
@ -183,7 +183,7 @@
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(856, 453);
|
||||
ClientSize = new Size(856, 541);
|
||||
Controls.Add(btnStartRead);
|
||||
Controls.Add(lblTransFileName);
|
||||
Controls.Add(btnChooseFile);
|
||||
|
||||
@ -17,6 +17,7 @@ namespace WinFormDiApp
|
||||
_accountRecordRepository = accountRecordRepository;
|
||||
_readingIn = readingIn;
|
||||
_logger = logger;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -42,10 +43,11 @@ namespace WinFormDiApp
|
||||
if (!_readingIn.ReadAndSaveInvoices(lblTransFileName.Text))
|
||||
{
|
||||
var resUlt = _readingIn.readXLS(lblTransFileName.Text);
|
||||
resUlt.ToList().ForEach(rec => _logger.LogInformation($"Konto :{rec.Konto}, {rec.Belopp}"));
|
||||
resUlt.ToList().ForEach(rec => _logger.LogInformation("Konto :{sKonto}, {dBelopp}", rec.Konto, rec.Belopp));
|
||||
}
|
||||
else
|
||||
{
|
||||
lvPayouts.Items.Clear();
|
||||
var payments = _accountRecordRepository.GetAllAccounts();
|
||||
foreach (var account in payments)
|
||||
{
|
||||
@ -61,5 +63,7 @@ namespace WinFormDiApp
|
||||
btnStartRead.Enabled = false;
|
||||
btnStartRead.Visible = false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -120,4 +120,7 @@
|
||||
<metadata name="ofChooseFile.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>25</value>
|
||||
</metadata>
|
||||
</root>
|
||||
@ -14,6 +14,7 @@ namespace WinFormDiApp.BL.Models
|
||||
public string Konto { get; set; } = string.Empty;
|
||||
public double Belopp { get; set; }
|
||||
public string Avisering { get; set; } = string.Empty;
|
||||
public DateTime Stored { get; set;} = DateTime.Now.ToLocalTime();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,8 +11,23 @@ namespace WinFormDiApp.DAL
|
||||
|
||||
public virtual DbSet<Member> Members { get; set; }
|
||||
public virtual DbSet<AccountRecord> AccountRecords { get; set; }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<AccountRecord>()
|
||||
.HasIndex(e => new
|
||||
{
|
||||
e.BetalDatum,
|
||||
e.Belopp,
|
||||
e.Konto
|
||||
})
|
||||
.IsUnique();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public class DesignTimeDbContextFactory : IDesignTimeDbContextFactory<ApplicationDbContext>
|
||||
{
|
||||
public ApplicationDbContext CreateDbContext(string[] args)
|
||||
|
||||
88
WinFormDiApp.DAL/Migrations/20230901070448_storingdate.Designer.cs
generated
Normal file
88
WinFormDiApp.DAL/Migrations/20230901070448_storingdate.Designer.cs
generated
Normal file
@ -0,0 +1,88 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using WinFormDiApp.DAL;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace WinFormDiApp.DAL.Migrations
|
||||
{
|
||||
[DbContext(typeof(ApplicationDbContext))]
|
||||
[Migration("20230901070448_storingdate")]
|
||||
partial class storingdate
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder.HasAnnotation("ProductVersion", "7.0.10");
|
||||
|
||||
modelBuilder.Entity("WinFormDiApp.BL.Models.AccountRecord", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Avisering")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<double>("Belopp")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<DateTime>("BetalDatum")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Konto")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Mottagare")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("Stored")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("AccountRecords");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("WinFormDiApp.BL.Models.Member", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("FirstName")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("LastName")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("NickName")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("PersonType")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Members");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
30
WinFormDiApp.DAL/Migrations/20230901070448_storingdate.cs
Normal file
30
WinFormDiApp.DAL/Migrations/20230901070448_storingdate.cs
Normal file
@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace WinFormDiApp.DAL.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class storingdate : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<DateTime>(
|
||||
name: "Stored",
|
||||
table: "AccountRecords",
|
||||
type: "TEXT",
|
||||
nullable: false,
|
||||
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "Stored",
|
||||
table: "AccountRecords");
|
||||
}
|
||||
}
|
||||
}
|
||||
91
WinFormDiApp.DAL/Migrations/20230903161124_multikey.Designer.cs
generated
Normal file
91
WinFormDiApp.DAL/Migrations/20230903161124_multikey.Designer.cs
generated
Normal file
@ -0,0 +1,91 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using WinFormDiApp.DAL;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace WinFormDiApp.DAL.Migrations
|
||||
{
|
||||
[DbContext(typeof(ApplicationDbContext))]
|
||||
[Migration("20230903161124_multikey")]
|
||||
partial class multikey
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder.HasAnnotation("ProductVersion", "7.0.10");
|
||||
|
||||
modelBuilder.Entity("WinFormDiApp.BL.Models.AccountRecord", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Avisering")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<double>("Belopp")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<DateTime>("BetalDatum")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Konto")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Mottagare")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("Stored")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BetalDatum", "Belopp", "Konto")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("AccountRecords");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("WinFormDiApp.BL.Models.Member", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("FirstName")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("LastName")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("NickName")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("PersonType")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Members");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
28
WinFormDiApp.DAL/Migrations/20230903161124_multikey.cs
Normal file
28
WinFormDiApp.DAL/Migrations/20230903161124_multikey.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace WinFormDiApp.DAL.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class multikey : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_AccountRecords_BetalDatum_Belopp_Konto",
|
||||
table: "AccountRecords",
|
||||
columns: new[] { "BetalDatum", "Belopp", "Konto" },
|
||||
unique: true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_AccountRecords_BetalDatum_Belopp_Konto",
|
||||
table: "AccountRecords");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -41,8 +41,14 @@ namespace WinFormDiApp.DAL.Migrations
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("Stored")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BetalDatum", "Belopp", "Konto")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("AccountRecords");
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user