コード例 #1
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();
        }
コード例 #2
0
        private LoggingEventData CreateEventData(
            Level level, object message, Exception t, PropertiesCollectionEx props)
        {
            LoggingEventData data = new LoggingEventData();

            data.Message         = message.ToString();
            data.ExceptionString = t == null?null:t.ToString();
            data.Properties      = props == null ?null:props.PropertiesCollection;
            data.LocationInfo    = new LocationInfo(_slogType);
            data.Domain          = _domainName;

            data.LoggerName   = _logger.Name;
            data.Level        = level;
            data.TimeStampUtc = DateTime.UtcNow;

            return(data);
        }
コード例 #3
0
 public void Fatal(PropertiesCollectionEx props, object message)
 {
     Fatal(props, message, null);
 }
コード例 #4
0
 public void Error(PropertiesCollectionEx props, object message)
 {
     Error(props, message, null);
 }
コード例 #5
0
 public void Warn(PropertiesCollectionEx props, object message)
 {
     Warn(props, message, null);
 }
コード例 #6
0
 public void Info(PropertiesCollectionEx props, object message)
 {
     Info(props, message, null);
 }
コード例 #7
0
 public void Debug(PropertiesCollectionEx props, object message)
 {
     Debug(props, message, null);
 }