Help needed !

Jul 7, 2009 at 12:17 PM

Hi Daniel,

I'm experiencing a problem which I'm not able to identify and I need your expertise on it !

My app is using the CAL (like Calcium) and, obiously, CLog for the ILoggerFacade of the CAL. I don't know why but on the CLog service side (ClogService.svc.cs) when instantiating a new ClientConfigurationData, the Log.GetLogLevel(info) always return LogLevel.None ! It used to work fine !

log4net is loading the configuration without any error so as CLog's LogManager. Here it is for reference :

	<Clog xmlns="http://danielvaughan.orpius.com/Clog/2/0/" InternalLogLevel="All" SkipFrameCount="4" >
		<LogStrategy Name="Log4Net" Type="DanielVaughan.Logging.LogStrategies.Log4NetStrategy, DanielVaughan.Logging.Log4NetLogStrategy"  />
	</Clog>
	<log4net debug="true">
		<appender name="FileAppender" type="log4net.Appender.FileAppender">
			<File value="log/CBS.CPBBMO.Web.log" />
			<AppendToFile value="true" />
			<layout type="log4net.Layout.PatternLayout">
				<Header value="[Header]&#xD;&#xA;" />
				<Footer value="[-------------------------------------------------------------------------]&#xD;&#xA;" />
				<ConversionPattern value="%date %thread %level		%message%newline"         />
			</layout>
		</appender>
		<appender name="TraceAppender" type="log4net.Appender.TraceAppender">
			<layout type="log4net.Layout.PatternLayout">
				<conversionPattern value="%-5level [%property{UserName}] - %message%newline" />
			</layout>
		</appender>
		<root>
			<level value="ALL"/>
			<appender-ref ref="FileAppender"/>
			<appender-ref ref="TraceAppender"/>
		</root>
		<logger name="CBS.CPBBMO.Infrastructure.CALExtensions.Log4NetLogger,/cbs.cpbbmo.web/default.aspx">
			<level value="ALL" />
			<appender-ref ref="FileAppender"/>
			<appender-ref ref="TraceAppender"/>
		</logger>
	</log4net>

 

Another weird thing is the multiple calls to ClogService's method GetConfiguration. It looks like the private member clientConfigurationData of the DanielVaughan.Logging.Log class never gets set !

Do you have any idea of what the problem might be ? do you need more information ?
Any information would be valuable at this point !

 

Thank you,

-jeff.

 

<Clog xmlns="http://danielvaughan.orpius.com/Clog/2/0/" InternalLogLevel="All" SkipFrameCount="4" >
<LogStrategy Name="Log4Net" Type="DanielVaughan.Logging.LogStrategies.Log4NetStrategy, DanielVaughan.Logging.Log4NetLogStrategy"  />
</Clog>
<!-- log4net [DV] -->
<log4net debug="true">
<!-- debug="true"  -->
<appender name="FileAppender" type="log4net.Appender.FileAppender">
<File value="log/CBS.CPBBMO.Web.log" />
<!-- Example using environment variables in params -->
<!-- <file value="${TMP}\log-file.txt" /> -->
<AppendToFile value="true" />
<!-- An alternate output encoding can be specified -->
<!-- <encoding value="unicodeFFFE" /> -->
<layout type="log4net.Layout.PatternLayout">
<Header value="[Header]&#xD;&#xA;" />
<Footer value="[-------------------------------------------------------------------------]&#xD;&#xA;" />
<ConversionPattern value="%date %thread %level %message%newline"         />
</layout>
<!-- Alternate layout using XML -->
<!-- <layout type="log4net.Layout.XMLLayout" /> -->
</appender>
<appender name="TraceAppender" type="log4net.Appender.TraceAppender">
<layout type="log4net.Layout.PatternLayout">
<!-- <conversionPattern value="%-5level [%property{UserName}] - %message%newline" /> -->
<conversionPattern value="%-5level [%property{UserName}] - %message%newline" />
</layout>
</appender>
<root>
<level value="ALL"/>
<appender-ref ref="FileAppender"/>
<appender-ref ref="TraceAppender"/>
</root>
<!-- Clog requires url in logger names to be lower case. 
When using Clog on localhost, paths are relative. -->
<logger name="CBS.CPBBMO.Infrastructure.CALExtensions.Log4NetLogger,/cbs.cpbbmo.web/default.aspx">
<level value="ALL" />
<appender-ref ref="FileAppender"/>
<appender-ref ref="TraceAppender"/>
</logger>
<logger name="CBS.CPBBMO.Shell,/cbs.cpbbmo.web/default.aspx">
<level value="ALL" />
<appender-ref ref="FileAppender"/>
<appender-ref ref="TraceAppender"/>
</logger>
</log4net>
Coordinator
Jul 7, 2009 at 6:56 PM

Hi Jeff,

If you are using Calcium as an example then that would explain it. I just noticed that the Log4Net.config wasn’t being resolved correctly on the server. Log4Net wasn’t able to find its config, so it was causing the Log Level to be None.

In the Global.asax.cs I made some changes changed:

string rootDirectory = Server.MapPath("~");
log4net.Config.XmlConfigurator.Configure(new FileInfo(rootDirectory + "Log4Net.config")); //or “web.config” if that’s the way you’re doing things. 

Leave the other issue with me.

Thanks for your message.

Cheers,

Daniel

Jul 8, 2009 at 10:26 AM

Hi Daniel,

Thanks for your response.

No, I’m not using Calcium, which is something I might regret now but I’m an early adopter of the PRISM V2  implementation for Silverlight (since drop 5 actually) and while developing my app I needed all the stuff you’ve put in Calcium (a log system, a messaging one, …). For the logging system I decided to go with Clog and for the (one way)messaging, if you could see my implementation, you would laugh out loud (a CAL event listen to by the Shell, and sent by modules !). Next step is what you’ve called the user affinity module… Oh well…

Regarding my problem, the config file is well read by log4net (I’ve set debug to true and I can see log4net messages from the console).

Something I didn’t tell you about my implementation is the way I integrate Clog in the CAL. First the class that implements ILoggerFacade :

 

 

namespace CBS.CPBBMO.Infrastructure.CALExtensions
{
    public class Log4NetLogger : ILoggerFacade
    {
        private static readonly ILog logger = LogManager.GetLog(MethodBase.GetCurrentMethod().DeclaringType);

        #region ILoggerFacade Members

        public void Log(string message, Category category, Priority priority)
        {
            switch (category)
            {
                case Category.Debug:
                    logger.Debug(message);
                    break;

                case Category.Exception:
                    logger.Error(message);
                    break;

                case Category.Warn:
                    logger.Warn(message);
                    break;

                default:
                    logger.Info(message);
                    break;
            }
        }

        #endregion
    }
}

 Then in the bootstrapper:

 

 

namespace CBS.CPBBMO
{
    public class Bootstrapper : UnityBootstrapper
    {
        private IModuleManager moduleManager;
        private IRegionManager regionManager;
        private IEventAggregator eventAggregator;
        private Log4NetLogger logger = new Log4NetLogger();

        protected override ILoggerFacade LoggerFacade
        {
            get
            {
                return logger;
            }
        }
 […]
     }
}


 

 

Any idea ??

 

Thanks,

-jeff.

Jul 8, 2009 at 2:07 PM

Hi Daniel,

I found the solution ! The Core and Log4NetLogStrategy were referencing a different log4net DLL than the one used for the web application !

Thank you for your post. It put me in the correct direction (config file not loaded properly).

I'm going to download and take a peek at Calcium now to see in which manner you extended PRISM. :)

Thanks again,
-jeff. 

Coordinator
Jul 8, 2009 at 4:52 PM

Thanks for letting me know Jeff. Glad you found out what it was.

Cheers,
Daniel