コード例 #1
0
        private Logger()
        {
            Getlog4netConfigLocation("IKTA.Common");
            // Create the logger using the ProjectName property value from the .btdfproj
            logger = SLogManager.GetLogger("IKTA.Common", CallersTypeName.Name);

            // Configure the logger by referencing the registry key written during the deployment process
            logger.RegistryConfigurator();
        }
コード例 #2
0
        static void Main(string[] args)
        {
            // Note - a registry key must exist under hklm/software for this string below
            string domain = "log4net.Ext.Serializable.UnitTest1.2.10";
            SLog   log    = (SLog)SLogManager.GetLogger(domain, typeof(TestSerializableLog));

            log.RegistryConfigurator();

            PropertiesCollectionEx props = new PropertiesCollectionEx();

            props.Set("TESTPROP", "myprop");

            log.InfoFormat(props, "Hello world with myprop for a prop {0}", log.GetHashCode());
            ((ILog)log).DebugFormat("Shouldn't see this - its a debug.");

            SLog log2 = (SLog)SLogManager.GetLogger(domain, typeof(TestSerializableLog));

            log2.Info("Hello world again - different SLog reference, same SLog?  Look for myprop prop " +  +log2.GetHashCode());

            MemoryStream  stream    = new MemoryStream();
            SoapFormatter formatter = new SoapFormatter();

            formatter.Serialize(stream, log);
            formatter.Serialize(stream, props);
            System.Text.Encoding encoding = System.Text.Encoding.UTF8;
            string ser = encoding.GetString(stream.ToArray());

            //log.Info("log looks like: " + ser);

            stream.Seek(0, System.IO.SeekOrigin.Begin);
            SoapFormatter          formatter2 = new SoapFormatter();
            SLog                   log3       = (SLog)formatter2.Deserialize(stream);
            PropertiesCollectionEx props2     = (PropertiesCollectionEx)formatter2.Deserialize(stream);

            log3.Info(props2, "Hello world from deserialized stream.  Look for myprop prop. " +  +log3.GetHashCode());

            SLog log4 = (SLog)SLogManager.GetLogger(domain, typeof(TestSerializableLog));

            log4.Info("Hello world again - different SLog reference, same SLog?  Look for myprop prop. " + log4.GetHashCode());


            log4.Info(string.Format("Hash codes: {0} {1} {2} {3}", log.Logger.GetHashCode(),
                                    log2.Logger.GetHashCode(),
                                    log3.Logger.GetHashCode(),
                                    log4.Logger.GetHashCode()));

            Console.ReadLine();
        }