Add new Backend structure with proper .NET 8 projects
This commit is contained in:
46
src/Backend/DiunaBI.WebAPI/Controllers/LogsController.cs
Normal file
46
src/Backend/DiunaBI.WebAPI/Controllers/LogsController.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using DiunaBI.Core.Models;
|
||||
using Google.Cloud.Firestore;
|
||||
|
||||
namespace DiunaBI.WebAPI.Controllers;
|
||||
|
||||
public class LogsController : Controller
|
||||
{
|
||||
|
||||
private readonly FirestoreDb _firestoreDb;
|
||||
private readonly Guid _SessionId = Guid.NewGuid();
|
||||
public LogsController(
|
||||
FirestoreDb firestoreDb
|
||||
)
|
||||
{
|
||||
_firestoreDb = firestoreDb;
|
||||
}
|
||||
|
||||
public void AddEntry(LogEntry entry)
|
||||
{
|
||||
entry.SessionId = _SessionId;
|
||||
entry.Instance = LogInstance.Morska;
|
||||
|
||||
if (entry.Type == LogEntryType.Info) { return; }
|
||||
|
||||
try
|
||||
{
|
||||
var collection = _firestoreDb.Collection("ApiLogs");
|
||||
var document = collection.Document();
|
||||
document.SetAsync(new
|
||||
{
|
||||
entry.Message,
|
||||
entry.Title,
|
||||
Type = Enum.GetName(typeof(LogEntryType), entry.Type),
|
||||
LogType = Enum.GetName(typeof(LogType), entry.LogType),
|
||||
Instance = Enum.GetName(typeof(LogInstance), entry.Instance),
|
||||
entry.CreatedAt,
|
||||
SessionId = entry.SessionId.ToString()
|
||||
}).Wait();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user