Skip to content

Commit

Permalink
file handler and method parsing fix
Browse files Browse the repository at this point in the history
  • Loading branch information
JerryImMouse committed Jun 27, 2024
1 parent c90e160 commit 0a14710
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
11 changes: 9 additions & 2 deletions Jerry.Utilities/HttpUtility/HttpContext.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Net;
using System.Text;
using System.Text.Json;
using Jerry.Utilities.Utility;
using Method = Jerry.Utilities.HttpUtility.HttpMethod;
namespace Jerry.Utilities.HttpUtility;

Expand All @@ -25,9 +26,15 @@ public class HttpContext
#region Private
private void ParseHttpMethod()
{
if (!Enum.TryParse(_nativeContext.Request.HttpMethod, out Method method))
var method = _nativeContext.Request.HttpMethod;

method = method
.ToLower()
.CapitalizeFirstLetter();

if (!Enum.TryParse(method, out Method parsedMethod))
HttpMethod = Method.Get;
HttpMethod = method;
HttpMethod = parsedMethod;
}

private Dictionary<string, string> GetHeaders()
Expand Down
16 changes: 15 additions & 1 deletion Jerry.Utilities/Logging/Handlers/FileLogHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,30 @@
#endregion --- License ---

using System.Text;
using Jerry.Utilities.IoC.General;
using Jerry.Utilities.Logging.Interfaces;
using Jerry.Utilities.Logging.LogStructs;
using Serilog.Events;

namespace Jerry.Utilities.Logging.Handlers;

public class FileLogHandler : ILogHandler, IDisposable
{
private readonly TextWriter _writer;
private static FileLogHandler? _instance;

public static FileLogHandler Instance
{
get
{
if (_instance != null)
return _instance;

_instance = new FileLogHandler("./logs.log");
return _instance;

}
set => _instance = value;
}
public FileLogHandler(string path)
{
Directory.CreateDirectory(Path.GetDirectoryName(path)!);
Expand Down
2 changes: 1 addition & 1 deletion Jerry.Utilities/Logging/LogStructs/LogExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static List<ILogHandler> ToHandlers(this HandlerFlags flags)

if (flags.HasFlag(HandlerFlags.File))
{
handlerInstances.Add(new FileLogHandler("./logs.log"));
handlerInstances.Add(FileLogHandler.Instance);
}
//TODO: loki handler for advanced logging

Expand Down
14 changes: 14 additions & 0 deletions Jerry.Utilities/Utility/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Jerry.Utilities.Utility;

public static class StringExtensions
{
public static string CapitalizeFirstLetter(this string str)
{
if (str.Length == 0)
throw new NullReferenceException("String is null");

var array = str.ToCharArray();
array[0] = char.ToUpper(array[0]);
return new string(array);
}
}

0 comments on commit 0a14710

Please sign in to comment.