-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#168 wrap encoding in ColoredConsoleAppender for skipping preamble
- Loading branch information
1 parent
d6c95c0
commit ede020b
Showing
8 changed files
with
664 additions
and
516 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,13 @@ | ||
using log4net.Appender; | ||
using log4net.Core; | ||
using log4net.Layout; | ||
|
||
namespace log4net_611_lib; | ||
|
||
public class DerivedAppender: RollingFileAppender | ||
public class DerivedAppender : RollingFileAppender | ||
{ | ||
protected override void Append(LoggingEvent loggingEvent) | ||
{ | ||
loggingEvent.Properties["appender-class-name"] = nameof(DerivedAppender); | ||
base.Append(loggingEvent); | ||
} | ||
protected override void Append(LoggingEvent loggingEvent) | ||
{ | ||
loggingEvent.Properties["appender-class-name"] = nameof(DerivedAppender); | ||
base.Append(loggingEvent); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,48 @@ | ||
using System.Reflection; | ||
using log4net; | ||
using log4net.Config; | ||
using log4net_611_lib; | ||
|
||
var appPath = new Uri(Assembly.GetExecutingAssembly().Location).LocalPath; | ||
var appFolder = Path.GetDirectoryName(appPath); | ||
// force loading the assembly, otherwise the appender type isn't found later | ||
Assembly.LoadFile("log4net-611-lib.dll"); | ||
if (appFolder is null) | ||
{ | ||
throw new InvalidOperationException("Can't find myself"); | ||
throw new InvalidOperationException("Can't find myself"); | ||
} | ||
|
||
Assembly.LoadFile(Path.Combine(appFolder, "log4net-611-lib.dll")); | ||
|
||
var configFile = Path.Combine(appFolder, "log4net.config"); | ||
if (!File.Exists(configFile)) | ||
{ | ||
throw new InvalidOperationException($"log4net.config not found at {configFile}"); | ||
throw new InvalidOperationException($"log4net.config not found at {configFile}"); | ||
} | ||
|
||
if (Directory.Exists("Logs")) | ||
{ | ||
Console.WriteLine("Clearing out old logs..."); | ||
foreach (var file in Directory.EnumerateFiles("Logs")) | ||
{ | ||
File.Delete(file); | ||
} | ||
Console.WriteLine("Clearing out old logs..."); | ||
foreach (var file in Directory.EnumerateFiles("Logs")) | ||
{ | ||
File.Delete(file); | ||
} | ||
} | ||
|
||
var info = new FileInfo(configFile); | ||
var logRepo = LogManager.GetRepository(Assembly.GetExecutingAssembly()); | ||
XmlConfigurator.ConfigureAndWatch( | ||
logRepo, | ||
info | ||
); | ||
XmlConfigurator.ConfigureAndWatch(logRepo, info); | ||
|
||
var logger = LogManager.GetLogger(typeof(Program)); | ||
|
||
Console.WriteLine("logging..."); | ||
for (var i = 0; i < 10; i++) | ||
{ | ||
logger.Info($"test log {i}"); | ||
logger.Info($"test log {i}"); | ||
} | ||
|
||
|
||
foreach (var file in Directory.EnumerateFiles("Logs")) | ||
{ | ||
Console.WriteLine($"log file: {file}"); | ||
Console.WriteLine(File.ReadAllText(file)); | ||
Console.WriteLine($"log file: {file}"); | ||
Console.WriteLine(File.ReadAllText(file)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.