Skip to content

Commit 36b08b0

Browse files
authored
Logging/v2 (#6)
* Removed old log code * Rewritten log class * version number and moved to net standard 2.1 * Updated README.md
1 parent 4c1aa3f commit 36b08b0

File tree

8 files changed

+30
-103
lines changed

8 files changed

+30
-103
lines changed

CommonsLibrary.Logging/CommonsLibrary.Logging.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
<PropertyGroup>
44
<OutputType>Library</OutputType>
5-
<TargetFramework>net7.0</TargetFramework>
5+
<TargetFramework>netstandard2.1</TargetFramework>
66
<ImplicitUsings>disable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
99
<PackageId>Alex.CommonsLibrary.Logging</PackageId>
1010
<Title>C# Logging Agent</Title>
11-
<Version>1.0.1</Version>
11+
<Version>2.0.0</Version>
1212
<Authors>Alex O'Brien</Authors>
1313
<Description>This is the logging component of my open source C# library</Description>
1414
<Copyright>Open Source</Copyright>

CommonsLibrary.Logging/Error.cs

-18
This file was deleted.

CommonsLibrary.Logging/Log.cs

+28-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,36 @@
1-
namespace CommonsLibrary.Logging
1+
using System;
2+
using System.IO;
3+
4+
namespace CommonsLibrary.Logging
25
{
3-
public class Log : LogBuilder
6+
public class Log
47
{
5-
public Log(string error, string logMessage)
8+
private readonly string _filePath;
9+
private static Log? _logger;
10+
11+
private Log(string filePath) => _filePath = filePath;
12+
public static Log GetLogger(string filePath) => _logger ??= new Log(filePath);
13+
14+
private void WriteLog(LogLevel level, string message, Exception? exception = null)
615
{
7-
log = new Logs("LOG", error, logMessage);
16+
using StreamWriter writer = new StreamWriter(_filePath, true);
17+
writer.WriteLine($"{DateTime.Now} {level} {exception} {message}");
818
}
919

10-
public override void BuildLogMessage()
11-
{ }
20+
public void Info(string message) =>
21+
WriteLog(LogLevel.Info, message);
22+
23+
public void Warning(string message) =>
24+
WriteLog(LogLevel.Warning, message);
1225

13-
public override void BuildError()
14-
{ }
26+
public void Error(string message, Exception exception) =>
27+
WriteLog(LogLevel.Error, message, exception);
28+
29+
private enum LogLevel
30+
{
31+
Info,
32+
Warning,
33+
Error,
34+
}
1535
}
1636
}

CommonsLibrary.Logging/LogBuilder.cs

-12
This file was deleted.

CommonsLibrary.Logging/LogDirector.cs

-11
This file was deleted.

CommonsLibrary.Logging/Logs.cs

-31
This file was deleted.

CommonsLibrary.Logging/README.md

-5
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ This is my C# logging library for all of my personal C# projects.
55
## Index
66

77
- [Log](https://github.com/alex8obrien/CommonsLibrary/blob/master/CommonsLibrary.Logging/Log.cs)
8-
- [Warning](https://github.com/alex8obrien/CommonsLibrary/blob/master/CommonsLibrary.Logging/Warning.cs)
9-
- [Error](https://github.com/alex8obrien/CommonsLibrary/blob/master/CommonsLibrary.Logging/Error.cs)
10-
- [Builder Class](https://github.com/alex8obrien/CommonsLibrary/blob/master/CommonsLibrary.Logging/LogBuilder.cs)
11-
- [Director Class](https://github.com/alex8obrien/CommonsLibrary/blob/master/CommonsLibrary.Logging/LogDirector.cs)
12-
- [Base Log Class](https://github.com/alex8obrien/CommonsLibrary/blob/master/CommonsLibrary.Logging/Logs.cs)
138

149
## My Other C# Libraries
1510

CommonsLibrary.Logging/Warning.cs

-16
This file was deleted.

0 commit comments

Comments
 (0)