diff --git a/.github/dependabot.yml b/.github/dependabot.yml
index eea6c0f..e78fd88 100644
--- a/.github/dependabot.yml
+++ b/.github/dependabot.yml
@@ -6,7 +6,6 @@
version: 2
updates:
-
# github actions
- package-ecosystem: "github-actions"
# Workflow files stored in the
@@ -20,14 +19,6 @@ updates:
directory: "/src/WebApiBolierplate/API/" # Location of package manifests
schedule:
interval: "monthly"
- - package-ecosystem: "nuget" # See documentation for possible values
- directory: "/src/WebApiBolierplate/Model/" # Location of package manifests
- schedule:
- interval: "monthly"
- - package-ecosystem: "nuget" # See documentation for possible values
- directory: "/src/WebApiBolierplate/Business.Lib/" # Location of package manifests
- schedule:
- interval: "monthly"
- package-ecosystem: "nuget" # See documentation for possible values
directory: "/src/WebApiBolierplate/Core.Constants/" # Location of package manifests
schedule:
diff --git a/.github/workflows/CD.yml b/.github/workflows/CD.yml
index 55b9a4e..7e47947 100644
--- a/.github/workflows/CD.yml
+++ b/.github/workflows/CD.yml
@@ -30,8 +30,6 @@ jobs:
run: |
cd ./src/WebApiBolierplate
dotnet test ./Core.Test/Core.Test.csproj
- - name: IntelliCode Team Completions
- uses: microsoft/vs-intellicode@v1.0
build-linux:
runs-on: ubuntu-latest
steps:
diff --git a/.gitignore b/.gitignore
index 6795ae4..e54e1df 100644
--- a/.gitignore
+++ b/.gitignore
@@ -366,7 +366,6 @@ MigrationBackup/
FodyWeavers.xsd
# VS Code files for those working on multiple tools
-.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
diff --git a/.vscode/spellright.dict b/.vscode/spellright.dict
new file mode 100644
index 0000000..0987f19
--- /dev/null
+++ b/.vscode/spellright.dict
@@ -0,0 +1,8 @@
+startup
+appconfig
+appsettings.json
+src
+launchsettings.json
+editorconfig
+db
+Serilog
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 15c793a..ccda336 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## [6.1.0] - 2022-08-15
### Added
- Added dependency Injection
+ - Added Serilog
### Changed
- Updated the default port
@@ -17,6 +18,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Removed
- Removed config static class
+ - Removed StartupLib and Tasks Controller
+ - Removed csv logger
## [6.0.0] - 2022-07-16
### Added
diff --git a/src/WebApiBolierplate/API/API.csproj b/src/WebApiBolierplate/API/API.csproj
index 9102045..d084a26 100644
--- a/src/WebApiBolierplate/API/API.csproj
+++ b/src/WebApiBolierplate/API/API.csproj
@@ -10,7 +10,8 @@
-
+
+
diff --git a/src/WebApiBolierplate/API/Controllers/TasksController.cs b/src/WebApiBolierplate/API/Controllers/TasksController.cs
deleted file mode 100644
index 8dc5780..0000000
--- a/src/WebApiBolierplate/API/Controllers/TasksController.cs
+++ /dev/null
@@ -1,29 +0,0 @@
-using API.Operations;
-using Core.Constants;
-using Microsoft.AspNetCore.Authorization;
-using Microsoft.AspNetCore.Mvc;
-using Microsoft.Extensions.Configuration;
-
-namespace API.Controllers;
-
-[Route("api/tasks")]
-[ApiController]
-public class TasksController : CustomBaseController
-{
- private readonly StarupLib _startupLib;
- public IConfiguration Configuration { get; }
-
- public TasksController(IConfiguration configuration, StarupLib starupLib)
- {
- _startupLib = starupLib;
- Configuration = configuration;
- }
-
- [HttpPut("reload/config")]
- [Authorize(Roles = AuthRoles.Admin)]
- public IActionResult LoadConfig()
- {
- _startupLib.LoadConfig(Configuration);
- return webAPIHelper.CreateResponse(InfoTexts.Success);
- }
-}
diff --git a/src/WebApiBolierplate/API/Helpers/JWTHelper.cs b/src/WebApiBolierplate/API/Helpers/JWTHelper.cs
index c79f3c7..9c1eb67 100644
--- a/src/WebApiBolierplate/API/Helpers/JWTHelper.cs
+++ b/src/WebApiBolierplate/API/Helpers/JWTHelper.cs
@@ -17,8 +17,8 @@ public class JWTHelper
public JWTHelper(IConfiguration configuration)
{
- _securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_configuration["AppConfig:JWT:Key"]));
_configuration = configuration;
+ _securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_configuration["AppConfig:JWT:Key"]));
}
#region [Token Generation]
diff --git a/src/WebApiBolierplate/API/Operations/Base.cs b/src/WebApiBolierplate/API/Operations/Base.cs
index f085e3f..5e4ddb2 100644
--- a/src/WebApiBolierplate/API/Operations/Base.cs
+++ b/src/WebApiBolierplate/API/Operations/Base.cs
@@ -10,13 +10,11 @@ public class Base
public DBAdapter dBAdapter;
public Core.Lib.Helpers helper;
- public CsvLogger csvLogger;
#endregion [Declarations]
public Base(IConfiguration configuration)
{
- csvLogger = new CsvLogger();
helper = new Core.Lib.Helpers();
// uncomment this line when there is a valid connection string
diff --git a/src/WebApiBolierplate/API/Operations/StarupLib.cs b/src/WebApiBolierplate/API/Operations/StarupLib.cs
deleted file mode 100644
index a9ec48c..0000000
--- a/src/WebApiBolierplate/API/Operations/StarupLib.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-using Core.Constants;
-using Microsoft.Extensions.Configuration;
-using System;
-
-namespace API.Operations;
-
-public class StarupLib
-{
- public StarupLib()
- {
-
- }
-
- public void LoadConfig(IConfiguration configuration)
- {
- Config.Logger.DateFormat = configuration["AppConfig:Logger:DateFormat"];
- Config.Logger.FileName = configuration["AppConfig:Logger:FileName"];
- Config.Logger.RelativePath = configuration["AppConfig:Logger:RelativePath"];
- Config.Logger.ReplacementValue = configuration["AppConfig:Logger:ReplacementValue"][0];
- }
-}
diff --git a/src/WebApiBolierplate/API/Operations/UserLib.cs b/src/WebApiBolierplate/API/Operations/UserLib.cs
index a03519b..6c02a32 100644
--- a/src/WebApiBolierplate/API/Operations/UserLib.cs
+++ b/src/WebApiBolierplate/API/Operations/UserLib.cs
@@ -8,10 +8,11 @@ public class UserLib : Base
{
private const string BrandonStark = "Brandon Stark";
private const string EddardStark = "Eddard Stark";
+ private readonly ILogger _logger;
- public UserLib(IConfiguration configuration): base(configuration)
+ public UserLib(IConfiguration configuration, ILogger logger): base(configuration)
{
-
+ _logger = logger;
}
public int ValidateLogin(LoginDTO login)
@@ -42,7 +43,7 @@ public int ValidateLogin(LoginDTO login)
}
catch (Exception ex)
{
- csvLogger.Error(ex);
+ _logger.LogError("ValidateLogin - {message}", ex.Message);
return -1;
}
}
@@ -63,7 +64,7 @@ public User GetUser(string userName)
}
catch (Exception ex)
{
- csvLogger.Error(ex);
+ _logger.LogError("GetUser - {message}", ex.Message);
return null;
}
}
diff --git a/src/WebApiBolierplate/API/Program.cs b/src/WebApiBolierplate/API/Program.cs
index 1d260d6..edf3a4f 100644
--- a/src/WebApiBolierplate/API/Program.cs
+++ b/src/WebApiBolierplate/API/Program.cs
@@ -1,14 +1,16 @@
using API.Helpers;
using API.Operations;
-using Core.Constants;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Mvc;
+using Microsoft.Extensions.Configuration;
using Microsoft.IdentityModel.Tokens;
using Microsoft.OpenApi.Models;
using System.Text;
var builder = WebApplication.CreateBuilder(args);
+builder.Logging.AddFile("Logs/API.log");
+
// To prevent .NET and server info from being added to header if Kestrel is used
builder.WebHost.ConfigureKestrel(serverOptions => {
serverOptions.AddServerHeader = false;
@@ -16,16 +18,12 @@
#region Configuring Services
-var startupLib = new StarupLib();
-startupLib.LoadConfig(builder.Configuration);
-
builder.Services.AddControllers();
#region Dependency Injection
#region operations
-builder.Services.AddScoped();
builder.Services.AddScoped();
builder.Services.AddScoped();
diff --git a/src/WebApiBolierplate/API/appsettings.Development.json b/src/WebApiBolierplate/API/appsettings.Development.json
index 7de9adc..027316a 100644
--- a/src/WebApiBolierplate/API/appsettings.Development.json
+++ b/src/WebApiBolierplate/API/appsettings.Development.json
@@ -1,7 +1,7 @@
{
"Logging": {
"LogLevel": {
- "Default": "Debug",
+ "Default": "Information",
"System": "Information",
"Microsoft": "Information"
}
@@ -10,12 +10,6 @@
"DataBase": {
"ConnectionString": "sample connection string"
},
- "Logger": {
- "DateFormat": "yyyy-MM-dd HH:mm:ss.fff",
- "FileName": "ErrorLog",
- "RelativePath": "",
- "ReplacementValue": ";"
- },
"JWT": {
"Audience": "https://www.example.com",
"Issuer": "WebApiBoilerplate",
diff --git a/src/WebApiBolierplate/API/appsettings.production.json b/src/WebApiBolierplate/API/appsettings.production.json
index 40229d6..24093f7 100644
--- a/src/WebApiBolierplate/API/appsettings.production.json
+++ b/src/WebApiBolierplate/API/appsettings.production.json
@@ -8,12 +8,6 @@
"DataBase": {
"ConnectionString": "sample connection string"
},
- "Logger": {
- "DateFormat": "yyyy-MM-dd HH:mm:ss.fff",
- "FileName": "ErrorLog",
- "RelativePath": "",
- "ReplacementValue": ";"
- },
"JWT": {
"Audience": "https://www.example.com",
"Issuer": "WebApiBoilerplate",
diff --git a/src/WebApiBolierplate/Core.Constants/Config.cs b/src/WebApiBolierplate/Core.Constants/Config.cs
deleted file mode 100644
index b37a51c..0000000
--- a/src/WebApiBolierplate/Core.Constants/Config.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-namespace Core.Constants;
-
-///
-/// A class to store config values. Values assigned at startup Avoids reading from config file everytime.
-///
-public static class Config
-{
- ///
- /// Configuration for CSV logger
- ///
- public static class Logger
- {
- public static string DateFormat { get; set; }
- public static string FileName { get; set; }
- public static string RelativePath { get; set; }
- public static char ReplacementValue { get; set; }
- }
-}
diff --git a/src/WebApiBolierplate/Core.Lib/Core.Lib.csproj b/src/WebApiBolierplate/Core.Lib/Core.Lib.csproj
index 7a8509d..1ea29da 100644
--- a/src/WebApiBolierplate/Core.Lib/Core.Lib.csproj
+++ b/src/WebApiBolierplate/Core.Lib/Core.Lib.csproj
@@ -6,8 +6,7 @@
-
-
+
diff --git a/src/WebApiBolierplate/Core.Lib/CsvLogger.cs b/src/WebApiBolierplate/Core.Lib/CsvLogger.cs
deleted file mode 100644
index 237988f..0000000
--- a/src/WebApiBolierplate/Core.Lib/CsvLogger.cs
+++ /dev/null
@@ -1,93 +0,0 @@
-using Core.Constants;
-using System;
-
-namespace Core.Lib;
-
-public class CsvLogger
-{
- #region [Declarations]
-
- private nk.logger.csv.Logger csvLogger;
-
- #endregion [Declarations]
-
- ///
- /// Initiate an instance of Logger class.
- ///
- public CsvLogger()
- {
- var config = new nk.logger.csv.LoggerConfig()
- .SetDateTimeFormat(Config.Logger.DateFormat)
- .SetFileName(Config.Logger.FileName)
- .SetRelativePath(Config.Logger.RelativePath)
- .SetReplacementValue(Config.Logger.ReplacementValue);
-
- csvLogger = new nk.logger.csv.Logger(config);
- }
-
- #region [Public Logger functions]
-
- #region [Exception Logs]
-
- ///
- /// Log an as DEBUG
- ///
- ///
- public void Debug(Exception ex) => csvLogger.Debug(ex);
-
- ///
- /// Log an as ERROR
- ///
- ///
- public void Error(Exception ex) => csvLogger.Error(ex);
-
- ///
- /// Log an as Fatal
- ///
- ///
- public void Fatal(Exception ex) => csvLogger.Fatal(ex);
-
- #endregion [Exception Logs]
-
- #region [Error message logs]
-
- ///
- /// Log a DEBUG message
- ///
- /// Message
- public void Debug(string text) => csvLogger.Debug(text);
-
- ///
- /// Log an ERROR message
- ///
- /// Message
- public void Error(string text) => csvLogger.Error(text);
-
- ///
- /// Log a FATAL ERROR message
- ///
- /// Message
- public void Fatal(string text) => csvLogger.Fatal(text);
-
- ///
- /// Log an INFO message
- ///
- /// Message
- public void Info(string text) => csvLogger.Info(text);
-
- ///
- /// Log a TRACE message
- ///
- /// Message
- public void Trace(string text) => csvLogger.Trace(text);
-
- ///
- /// Log a WARNING message
- ///
- /// Message
- public void Warning(string text) => csvLogger.Warning(text);
-
- #endregion [Error message logs]
-
- #endregion [Public Logger functions]
-}
diff --git a/src/WebApiBolierplate/Core.Lib/Security/EncryptionHelper.cs b/src/WebApiBolierplate/Core.Lib/Security/EncryptionHelper.cs
index a74c1dd..69b2a74 100644
--- a/src/WebApiBolierplate/Core.Lib/Security/EncryptionHelper.cs
+++ b/src/WebApiBolierplate/Core.Lib/Security/EncryptionHelper.cs
@@ -8,7 +8,6 @@ namespace Core.Lib.Security;
///
/// This class offer simple encryption and decryption
-/// This function is taken from the following stack overflow answer with some modifications
/// Ref: https://stackoverflow.com/a/27484425/5407188
///
public class EncryptionHelper
diff --git a/src/WebApiBolierplate/Core.Test/Core.Test.csproj b/src/WebApiBolierplate/Core.Test/Core.Test.csproj
index 4f8ae13..64ab58b 100644
--- a/src/WebApiBolierplate/Core.Test/Core.Test.csproj
+++ b/src/WebApiBolierplate/Core.Test/Core.Test.csproj
@@ -7,7 +7,7 @@
-
+
diff --git a/src/postman/Web API Boilerplate.postman_collection.json b/src/postman/Web API Boilerplate.postman_collection.json
index 6fb65d3..524f5bc 100644
--- a/src/postman/Web API Boilerplate.postman_collection.json
+++ b/src/postman/Web API Boilerplate.postman_collection.json
@@ -3,7 +3,8 @@
"_postman_id": "e9a4c362-4912-4385-b212-60bfcd922d54",
"name": "Web API Boilerplate",
"description": "Postman collection for [https://github.com/kolappannathan/dotnet-web-api-boilerplate](https://github.com/kolappannathan/dotnet-web-api-boilerplate)\n\n* Set the api-url collection variable to point to the correct URL\n* Calling the login APIs will automatically update the bearer tokens",
- "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
+ "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
+ "_exporter_id": "11196299"
},
"item": [
{
@@ -253,33 +254,6 @@
}
]
},
- {
- "name": "Tasks Controller",
- "item": [
- {
- "name": "Reload config",
- "request": {
- "method": "PUT",
- "header": [],
- "body": {
- "mode": "raw",
- "raw": ""
- },
- "url": {
- "raw": "{{api-url}}tasks/reload/config",
- "host": [
- "{{api-url}}tasks"
- ],
- "path": [
- "reload",
- "config"
- ]
- }
- },
- "response": []
- }
- ]
- },
{
"name": "Values Controller",
"item": [
@@ -447,7 +421,7 @@
"variable": [
{
"key": "api-url",
- "value": "https://localhost:44332/api/"
+ "value": "https://localhost:7030/api/"
},
{
"key": "auth-token",