Issue with no Logger.Appenders even though log shows config successfully loaded

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Issue with no Logger.Appenders even though log shows config successfully loaded

John Gold
I would appreciate any help you can provide? Not sure what I am doing wrong...

I am creating a log4net compatibility library for my new Visual Studio tool ErrorUnit at https://github.com/JohnGoldInc/ErrorUnit.Logger_log4net

Line 37 of https://github.com/JohnGoldInc/ErrorUnit.Logger_log4net/blob/master/ErrorUnitLogger.cs has Count=0 Appenders even though my log shows that appenders were loaded:

...
16 namespace ErrorUnit.Logger_log4net
17 {
18    public class ErrorUnitLogger : ILogger
19    {
20        private static ILog log = LogManager.GetLogger(typeof(ErrorUnitLogger));
21
22        public IEnumerable<string> GetErrorUnitJson(DateTime afterdate)
23        {
24            var ErrorUnitJson = new ConcurrentBag<string>();
25            log4net.Util.LogLog.InternalDebugging = true; //todo remove
26            System.Diagnostics.Trace.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(@"f:\Temp\Logger_log4net.log", "myListener"));
27            System.Diagnostics.Trace.AutoFlush = true;
28            System.Diagnostics.Trace.TraceInformation("Test Logger_log4net message.");
29
30            var config = log4net.Config.XmlConfigurator.Configure();
31            log = LogManager.GetLogger(typeof(ErrorUnitLogger));
32
33            // Parallel.ForEach(logs, log => {
34            var log4net_Logger = log.Logger as log4net.Repository.Hierarchy.Logger;
35            if (log4net_Logger != null)
36            {
37                Parallel.ForEach(log4net_Logger.Appenders.Cast<log4net.Appender.IAppender>(), appender =>
...


devenv.exe Information: 0 : Test Logger_log4net message.
log4net: configuring repository [log4net-default-repository] using .config file section
log4net: Application config file is [F:\Documents\Visual Studio 2015\Projects\WebApplication1\WebApplication1.Tests\obj\Release]
log4net: Configuring Repository [log4net-default-repository]
log4net: Configuration update mode [Merge].
...
log4net: Created Appender [AdoNetAppender]
log4net: Adding appender named [AdoNetAppender] to logger [root].
log4net: Hierarchy Threshold []
...

Thanks!

Reply | Threaded
Open this post in threaded view
|

Re: Issue with no Logger.Appenders even though log shows config successfully loaded

John Gold
Fixed!,

Needed to go to the Logger.Parent to get the Appenders.


Also ErrorUnit is now compatible with log4net!

Generate Unit test replicating error logged in your environments!


On Sun, Dec 18, 2016 at 10:37 AM, John Gold <[hidden email]> wrote:
I would appreciate any help you can provide? Not sure what I am doing wrong...

I am creating a log4net compatibility library for my new Visual Studio tool ErrorUnit at https://github.com/JohnGoldInc/ErrorUnit.Logger_log4net

Line 37 of https://github.com/JohnGoldInc/ErrorUnit.Logger_log4net/blob/master/ErrorUnitLogger.cs has Count=0 Appenders even though my log shows that appenders were loaded:

...
16 namespace ErrorUnit.Logger_log4net
17 {
18    public class ErrorUnitLogger : ILogger
19    {
20        private static ILog log = LogManager.GetLogger(typeof(ErrorUnitLogger));
21
22        public IEnumerable<string> GetErrorUnitJson(DateTime afterdate)
23        {
24            var ErrorUnitJson = new ConcurrentBag<string>();
25            log4net.Util.LogLog.InternalDebugging = true; //todo remove
26            System.Diagnostics.Trace.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(@"f:\Temp\Logger_log4net.log", "myListener"));
27            System.Diagnostics.Trace.AutoFlush = true;
28            System.Diagnostics.Trace.TraceInformation("Test Logger_log4net message.");
29
30            var config = log4net.Config.XmlConfigurator.Configure();
31            log = LogManager.GetLogger(typeof(ErrorUnitLogger));
32
33            // Parallel.ForEach(logs, log => {
34            var log4net_Logger = log.Logger as log4net.Repository.Hierarchy.Logger;
35            if (log4net_Logger != null)
36            {
37                Parallel.ForEach(log4net_Logger.Appenders.Cast<log4net.Appender.IAppender>(), appender =>
...


devenv.exe Information: 0 : Test Logger_log4net message.
log4net: configuring repository [log4net-default-repository] using .config file section
log4net: Application config file is [F:\Documents\Visual Studio 2015\Projects\WebApplication1\WebApplication1.Tests\obj\Release]
log4net: Configuring Repository [log4net-default-repository]
log4net: Configuration update mode [Merge].
...
log4net: Created Appender [AdoNetAppender]
log4net: Adding appender named [AdoNetAppender] to logger [root].
log4net: Hierarchy Threshold []
...

Thanks!