You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by John Gold <jo...@johngoldinc.com> on 2016/12/18 15:37:00 UTC

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

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 =>
...

For the log ( the log without ellipsis is at https://github.com/
JohnGoldInc/ErrorUnit.Logger_log4net/blob/master/README.md ):

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!

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

Posted by John Gold <jo...@johngoldinc.com>.
Fixed!,

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

http://stackoverflow.com/questions/41210018/issue-with-no-log4net-logger-appenders-even-though-log-shows-config-successfully/42057416#42057416

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 <jo...@johngoldinc.com> 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(Er
> rorUnitLogger));
> 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_Logg
> er.Appenders.Cast<log4net.Appender.IAppender>(), appender =>
> ...
>
> For the log ( the log without ellipsis is at
> https://github.com/JohnGoldInc/ErrorUnit.Logger_log4net/
> blob/master/README.md ):
>
> 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!
>
>