示例#1
0
        public SyncServiceLogAppender this[long storeLocationID]
        {
            get
            {
                SyncServiceLogAppender handler = null;
                _items.TryGetValue(storeLocationID, out handler);
                string correctfileName = "";

                LoggerSimple.WriteMessage("handler found for storelocationid-" + storeLocationID + "-" + (handler != null).ToString());

                if (handler == null)
                {
                    try
                    {
                        handler = new SyncServiceLogAppender();

                        _items.Add(storeLocationID, handler);
                        handler.LastUsedDateTime = DateTime.Now;
                    }
                    catch (Exception ex)
                    {
                        LoggerSimple.WriteMessage(ex.Message);
                    }
                    finally
                    {
                        //context.Dispose();
                        //context = null;
                    }
                }



                return(handler);
            }
        }
示例#2
0
        public SyncServiceLogAppender(string fileLocation, long storeLocationID)
        {
            log4net.Repository.Hierarchy.Hierarchy repository = (log4net.Repository.Hierarchy.Hierarchy)log4net.LogManager.GetRepository();



            if (fileLocation != "")
            {
                LoggerSimple.WriteMessage("Creating logger...." + fileLocation);

                var appenders = repository.GetAppenders();

                if (appenders.FirstOrDefault(i => i.Name == "ASyncServiceLogAppender-" + storeLocationID) != null)
                {
                    return;
                }


                SyncServiceFileAppender originalAppender = appenders.FirstOrDefault(i => i.Name == "SyncServiceLogAppender-0") as SyncServiceFileAppender;
                //(appenders[0] as SyncServiceFileAppender);


                SyncServiceFileAppender fileAppender = new SyncServiceFileAppender();

                fileAppender.Name               = "ASyncServiceLogAppender-" + storeLocationID;
                fileAppender.File               = fileLocation;
                fileAppender.AppendToFile       = true;
                fileAppender.MaxSizeRollBackups = originalAppender.MaxSizeRollBackups;
                fileAppender.MaximumFileSize    = originalAppender.MaximumFileSize;
                fileAppender.RollingStyle       = originalAppender.RollingStyle;
                fileAppender.MaximumFileSize    = originalAppender.MaximumFileSize;
                fileAppender.CountDirection     = originalAppender.CountDirection;
                fileAppender.DatePattern        = originalAppender.DatePattern;
                fileAppender.ImmediateFlush     = originalAppender.ImmediateFlush;
                fileAppender.MaxFileSize        = originalAppender.MaxFileSize;


                fileAppender.StaticLogFileName = false;

                fileAppender.Threshold = log4net.Core.Level.All;

                fileAppender.Layout = originalAppender.Layout;

                fileAppender.LockingModel = new FileAppender.MinimalLock();

                fileAppender.ActivateOptions();

                fileAppender.FilePath = fileLocation;

                log4net.Repository.Hierarchy.Logger logger = (log4net.Repository.Hierarchy.Logger)repository.GetLogger("ASyncServiceLogAppender-" + storeLocationID);
                logger.AddAppender(fileAppender);

                LoggerSimple.WriteMessage("Logger Created..." + storeLocationID);

                Writer = LogManager.GetLogger("ASyncServiceLogAppender-" + storeLocationID);
            }
            else
            {
                Writer = LogManager.GetLogger("SyncServiceLogAppender-" + storeLocationID);
            }
        }