Modified Logger
This commit is contained in:
@@ -6,4 +6,8 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FireBird2D.Interfaces\Firebird2D.Interfaces.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Firebird2D.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -6,51 +7,72 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Firebird2D.Logger
|
||||
{
|
||||
public enum LogType
|
||||
{
|
||||
Info,
|
||||
Warning,
|
||||
Error
|
||||
}
|
||||
|
||||
public static class GameLogger
|
||||
public class GameLogger : ILogger
|
||||
{
|
||||
private static readonly string LogFilePath = "Logs/Log.txt";
|
||||
private string LogFilePath = "Logs/";
|
||||
|
||||
public static bool logActive { get { return _logActive; } set { _logActive = value; if (value == false) Log("Logger", LogType.Info, "Log Deactivated"); } }
|
||||
public bool LogActive { get { return _logActive; } set { _logActive = value; if (value == false) Log("Logger", LogType.Info, "Log Deactivated"); } }
|
||||
|
||||
private static bool _logActive = true;
|
||||
private bool _logActive = true;
|
||||
|
||||
public static void Initalize()
|
||||
private FileStream? fileStream;
|
||||
|
||||
private readonly object _fileLock = new();
|
||||
|
||||
private static readonly List<GameLogger> instances = [];
|
||||
|
||||
public int InstanceNumber { get; private set; }
|
||||
|
||||
private GameLogger(int instanceNumber, string instanceName)
|
||||
{
|
||||
LogFilePath += $"Log_{instanceName}.txt";
|
||||
InstanceNumber = instanceNumber;
|
||||
Initalize();
|
||||
}
|
||||
|
||||
public static ILogger GetNewInstance(string instanceName)
|
||||
{
|
||||
GameLogger instance = new(instances.Count, instanceName);
|
||||
instances.Add(instance);
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static ILogger GetInstance(int instanceNumber)
|
||||
{
|
||||
return instances[instanceNumber];
|
||||
}
|
||||
|
||||
private void Initalize()
|
||||
{
|
||||
if (!Directory.Exists("Logs"))
|
||||
{
|
||||
Directory.CreateDirectory("Logs");
|
||||
|
||||
using (FileStream fileStream = File.Open(LogFilePath, FileMode.OpenOrCreate | FileMode.Append))
|
||||
{
|
||||
AddText(fileStream, "===================" + System.DateTime.Today.ToString("dd,MM,yy") + "===================");
|
||||
}
|
||||
}
|
||||
|
||||
fileStream = File.Open(LogFilePath, FileMode.OpenOrCreate | FileMode.Append, FileAccess.Write, FileShare.Read);
|
||||
|
||||
lock (_fileLock)
|
||||
{
|
||||
AddText(fileStream, "===================" + DateTime.Now.ToString("dd.MM.yy HH:mm:ss") + "===================" + Environment.NewLine);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Log(string loggingInstance, LogType type, string message)
|
||||
public void Log(string loggingInstance, LogType type, string message)
|
||||
{
|
||||
if (_logActive)
|
||||
{
|
||||
using (FileStream fileStream = File.Open(LogFilePath, FileMode.OpenOrCreate | FileMode.Append))
|
||||
if (_logActive && fileStream != null)
|
||||
{
|
||||
lock (_fileLock)
|
||||
{
|
||||
AddText(fileStream, type.ToString("g") + ": " + loggingInstance + " -> " + message);
|
||||
fileStream.Close();
|
||||
AddText(fileStream, $"{DateTime.Now:HH:mm:ss} {type}: {loggingInstance} -> {message}{Environment.NewLine}");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static void AddText(FileStream fs, string value)
|
||||
{
|
||||
byte[] info = new UTF8Encoding(true).GetBytes(value);
|
||||
fs.Write(info, 0, info.Length);
|
||||
using StreamWriter writer = new(fs, Encoding.UTF8, 1024, leaveOpen: true);
|
||||
writer.Write(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Firebird2D.Logger
|
||||
{
|
||||
public enum LogType
|
||||
{
|
||||
Info,
|
||||
Warning,
|
||||
Error
|
||||
}
|
||||
|
||||
public interface ILogger
|
||||
{
|
||||
public bool LogActive { get; set; }
|
||||
|
||||
public int InstanceNumber { get; }
|
||||
|
||||
public abstract static ILogger GetNewInstance(string instanceName);
|
||||
|
||||
public abstract static ILogger GetInstance(int instanceNumber);
|
||||
|
||||
public void Log(string loggingInstance, LogType type, string message);
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ using System.Reflection;
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("Firebird2D.Logger")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+b4d5afc4ba4c2fb1fde6fb769da0e6c84003d734")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+51493135dfc8aa77e4285d80e32310c1f02be5b0")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("Firebird2D.Logger")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("Firebird2D.Logger")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
@@ -1 +1 @@
|
||||
affe20a17e8e88d1b9a30dd26c0c5847166b5692d8b48ab665b103d74ddc8438
|
||||
112eff4245416fbc9f49d96f1eeefaf18aad8e2f51adfc91c39b7f223783ed14
|
||||
|
||||
@@ -4,14 +4,14 @@
|
||||
"G:\\Coding\\Firebird2D\\Firebird2D.Logger\\Firebird2D.Logger.csproj": {}
|
||||
},
|
||||
"projects": {
|
||||
"G:\\Coding\\Firebird2D\\Firebird2D.Logger\\Firebird2D.Logger.csproj": {
|
||||
"G:\\Coding\\Firebird2D\\FireBird2D.Interfaces\\Firebird2D.Interfaces.csproj": {
|
||||
"version": "1.0.0",
|
||||
"restore": {
|
||||
"projectUniqueName": "G:\\Coding\\Firebird2D\\Firebird2D.Logger\\Firebird2D.Logger.csproj",
|
||||
"projectName": "Firebird2D.Logger",
|
||||
"projectPath": "G:\\Coding\\Firebird2D\\Firebird2D.Logger\\Firebird2D.Logger.csproj",
|
||||
"projectUniqueName": "G:\\Coding\\Firebird2D\\FireBird2D.Interfaces\\Firebird2D.Interfaces.csproj",
|
||||
"projectName": "Firebird2D.Interfaces",
|
||||
"projectPath": "G:\\Coding\\Firebird2D\\FireBird2D.Interfaces\\Firebird2D.Interfaces.csproj",
|
||||
"packagesPath": "C:\\Users\\wayan\\.nuget\\packages\\",
|
||||
"outputPath": "G:\\Coding\\Firebird2D\\Firebird2D.Logger\\obj\\",
|
||||
"outputPath": "G:\\Coding\\Firebird2D\\FireBird2D.Interfaces\\obj\\",
|
||||
"projectStyle": "PackageReference",
|
||||
"fallbackFolders": [
|
||||
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
|
||||
@@ -70,6 +70,77 @@
|
||||
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\8.0.303/PortableRuntimeIdentifierGraph.json"
|
||||
}
|
||||
}
|
||||
},
|
||||
"G:\\Coding\\Firebird2D\\Firebird2D.Logger\\Firebird2D.Logger.csproj": {
|
||||
"version": "1.0.0",
|
||||
"restore": {
|
||||
"projectUniqueName": "G:\\Coding\\Firebird2D\\Firebird2D.Logger\\Firebird2D.Logger.csproj",
|
||||
"projectName": "Firebird2D.Logger",
|
||||
"projectPath": "G:\\Coding\\Firebird2D\\Firebird2D.Logger\\Firebird2D.Logger.csproj",
|
||||
"packagesPath": "C:\\Users\\wayan\\.nuget\\packages\\",
|
||||
"outputPath": "G:\\Coding\\Firebird2D\\Firebird2D.Logger\\obj\\",
|
||||
"projectStyle": "PackageReference",
|
||||
"fallbackFolders": [
|
||||
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
|
||||
],
|
||||
"configFilePaths": [
|
||||
"C:\\Users\\wayan\\AppData\\Roaming\\NuGet\\NuGet.Config",
|
||||
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
|
||||
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
|
||||
],
|
||||
"originalTargetFrameworks": [
|
||||
"net8.0"
|
||||
],
|
||||
"sources": {
|
||||
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
|
||||
"C:\\Program Files\\dotnet\\library-packs": {},
|
||||
"C:\\TwinCAT\\Functions\\TE2000-HMI-Engineering\\Infrastructure\\Packages": {},
|
||||
"C:\\TwinCAT\\Functions\\TE2000-HMI-Engineering\\References": {},
|
||||
"https://api.nuget.org/v3/index.json": {}
|
||||
},
|
||||
"frameworks": {
|
||||
"net8.0": {
|
||||
"targetAlias": "net8.0",
|
||||
"projectReferences": {
|
||||
"G:\\Coding\\Firebird2D\\FireBird2D.Interfaces\\Firebird2D.Interfaces.csproj": {
|
||||
"projectPath": "G:\\Coding\\Firebird2D\\FireBird2D.Interfaces\\Firebird2D.Interfaces.csproj"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"warningProperties": {
|
||||
"warnAsError": [
|
||||
"NU1605"
|
||||
]
|
||||
},
|
||||
"restoreAuditProperties": {
|
||||
"enableAudit": "true",
|
||||
"auditLevel": "low",
|
||||
"auditMode": "direct"
|
||||
}
|
||||
},
|
||||
"frameworks": {
|
||||
"net8.0": {
|
||||
"targetAlias": "net8.0",
|
||||
"imports": [
|
||||
"net461",
|
||||
"net462",
|
||||
"net47",
|
||||
"net471",
|
||||
"net472",
|
||||
"net48",
|
||||
"net481"
|
||||
],
|
||||
"assetTargetFallback": true,
|
||||
"warn": true,
|
||||
"frameworkReferences": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"privateAssets": "all"
|
||||
}
|
||||
},
|
||||
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\8.0.303/PortableRuntimeIdentifierGraph.json"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,30 @@
|
||||
{
|
||||
"version": 3,
|
||||
"targets": {
|
||||
"net8.0": {}
|
||||
"net8.0": {
|
||||
"Firebird2D.Interfaces/1.0.0": {
|
||||
"type": "project",
|
||||
"framework": ".NETCoreApp,Version=v8.0",
|
||||
"compile": {
|
||||
"bin/placeholder/Firebird2D.Interfaces.dll": {}
|
||||
},
|
||||
"runtime": {
|
||||
"bin/placeholder/Firebird2D.Interfaces.dll": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"libraries": {
|
||||
"Firebird2D.Interfaces/1.0.0": {
|
||||
"type": "project",
|
||||
"path": "../FireBird2D.Interfaces/Firebird2D.Interfaces.csproj",
|
||||
"msbuildProject": "../FireBird2D.Interfaces/Firebird2D.Interfaces.csproj"
|
||||
}
|
||||
},
|
||||
"libraries": {},
|
||||
"projectFileDependencyGroups": {
|
||||
"net8.0": []
|
||||
"net8.0": [
|
||||
"Firebird2D.Interfaces >= 1.0.0"
|
||||
]
|
||||
},
|
||||
"packageFolders": {
|
||||
"C:\\Users\\wayan\\.nuget\\packages\\": {},
|
||||
@@ -41,7 +60,11 @@
|
||||
"frameworks": {
|
||||
"net8.0": {
|
||||
"targetAlias": "net8.0",
|
||||
"projectReferences": {}
|
||||
"projectReferences": {
|
||||
"G:\\Coding\\Firebird2D\\FireBird2D.Interfaces\\Firebird2D.Interfaces.csproj": {
|
||||
"projectPath": "G:\\Coding\\Firebird2D\\FireBird2D.Interfaces\\Firebird2D.Interfaces.csproj"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"warningProperties": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"version": 2,
|
||||
"dgSpecHash": "tcqAw3429hg=",
|
||||
"dgSpecHash": "DP1d2KMGQuQ=",
|
||||
"success": true,
|
||||
"projectFilePath": "G:\\Coding\\Firebird2D\\Firebird2D.Logger\\Firebird2D.Logger.csproj",
|
||||
"expectedPackageFiles": [],
|
||||
|
||||
Reference in New Issue
Block a user