示例#1
0
        public void AddSiteLog(int PortalId, int UserId, string Referrer, string URL, string UserAgent, string UserHostAddress, string UserHostName, int TabId, int AffiliateId, int SiteLogBuffer,
                               string SiteLogStorage)
        {
            var objSecurity = new PortalSecurity();

            try
            {
                // Disable site log buffering if site log buffering is enabled (i.e. SiteLogBuffer > 1), but caching should be disabled
                // Please note: Buffering is considered as some kind of caching, so disable caching should also disable buffering
                if (SiteLogBuffer > 1 && Host.PerformanceSetting == Globals.PerformanceSettings.NoCaching)
                {
                    SiteLogBuffer = 1;
                }

                switch (SiteLogBuffer)
                {
                case 0:     //logging disabled
                    break;

                case 1:     //no buffering
                    switch (SiteLogStorage)
                    {
                    case "D":         //database
                        _dataService.AddSiteLog(DateTime.Now,
                                                PortalId,
                                                UserId,
                                                objSecurity.InputFilter(Referrer, PortalSecurity.FilterFlag.NoScripting | PortalSecurity.FilterFlag.NoMarkup),
                                                objSecurity.InputFilter(URL, PortalSecurity.FilterFlag.NoScripting | PortalSecurity.FilterFlag.NoMarkup),
                                                objSecurity.InputFilter(UserAgent, PortalSecurity.FilterFlag.NoScripting | PortalSecurity.FilterFlag.NoMarkup),
                                                objSecurity.InputFilter(UserHostAddress, PortalSecurity.FilterFlag.NoScripting | PortalSecurity.FilterFlag.NoMarkup),
                                                objSecurity.InputFilter(UserHostName, PortalSecurity.FilterFlag.NoScripting | PortalSecurity.FilterFlag.NoMarkup),
                                                TabId,
                                                AffiliateId);
                        break;

                    case "F":         //file system
                        W3CExtendedLog(DateTime.Now,
                                       PortalId,
                                       UserId,
                                       objSecurity.InputFilter(Referrer, PortalSecurity.FilterFlag.NoScripting | PortalSecurity.FilterFlag.NoMarkup),
                                       objSecurity.InputFilter(URL, PortalSecurity.FilterFlag.NoScripting | PortalSecurity.FilterFlag.NoMarkup),
                                       objSecurity.InputFilter(UserAgent, PortalSecurity.FilterFlag.NoScripting | PortalSecurity.FilterFlag.NoMarkup),
                                       objSecurity.InputFilter(UserHostAddress, PortalSecurity.FilterFlag.NoScripting | PortalSecurity.FilterFlag.NoMarkup),
                                       objSecurity.InputFilter(UserHostName, PortalSecurity.FilterFlag.NoScripting | PortalSecurity.FilterFlag.NoMarkup),
                                       TabId,
                                       AffiliateId);
                        break;
                    }
                    break;

                default:     //buffered logging
                    string key        = "SiteLog" + PortalId;
                    var    arrSiteLog = (ArrayList)DataCache.GetCache(key);

                    //get buffered site log records from the cache
                    if (arrSiteLog == null)
                    {
                        arrSiteLog = new ArrayList();
                        DataCache.SetCache(key, arrSiteLog);
                    }

                    //create new sitelog object
                    var objSiteLog = new SiteLogInfo();
                    objSiteLog.DateTime        = DateTime.Now;
                    objSiteLog.PortalId        = PortalId;
                    objSiteLog.UserId          = UserId;
                    objSiteLog.Referrer        = objSecurity.InputFilter(Referrer, PortalSecurity.FilterFlag.NoScripting | PortalSecurity.FilterFlag.NoMarkup);
                    objSiteLog.URL             = objSecurity.InputFilter(URL, PortalSecurity.FilterFlag.NoScripting | PortalSecurity.FilterFlag.NoMarkup);
                    objSiteLog.UserAgent       = objSecurity.InputFilter(UserAgent, PortalSecurity.FilterFlag.NoScripting | PortalSecurity.FilterFlag.NoMarkup);
                    objSiteLog.UserHostAddress = objSecurity.InputFilter(UserHostAddress, PortalSecurity.FilterFlag.NoScripting | PortalSecurity.FilterFlag.NoMarkup);
                    objSiteLog.UserHostName    = objSecurity.InputFilter(UserHostName, PortalSecurity.FilterFlag.NoScripting | PortalSecurity.FilterFlag.NoMarkup);
                    objSiteLog.TabId           = TabId;
                    objSiteLog.AffiliateId     = AffiliateId;

                    //add sitelog object to cache
                    arrSiteLog.Add(objSiteLog);

                    if (arrSiteLog.Count >= SiteLogBuffer)
                    {
                        //create the buffered sitelog object
                        var objBufferedSiteLog = new BufferedSiteLog();
                        objBufferedSiteLog.SiteLogStorage = SiteLogStorage;
                        objBufferedSiteLog.SiteLog        = arrSiteLog;

                        //clear the current sitelogs from the cache
                        DataCache.RemoveCache(key);

                        //process buffered sitelogs on a background thread
                        var objThread = new Thread(objBufferedSiteLog.AddSiteLog);
                        objThread.Start();
                    }
                    break;
                }
            }
            catch (Exception exc)
            {
                Logger.Error(exc);
            }
        }
示例#2
0
        public void AddSiteLog(int PortalId, int UserId, string Referrer, string URL, string UserAgent, string UserHostAddress, string UserHostName, int TabId, int AffiliateId, int SiteLogBuffer,
                               string SiteLogStorage)
        {
            var objSecurity = new PortalSecurity();
            try
            {

                // Disable site log buffering if site log buffering is enabled (i.e. SiteLogBuffer > 1), but caching should be disabled
                // Please note: Buffering is considered as some kind of caching, so disable caching should also disable buffering
                if (SiteLogBuffer > 1 && Host.PerformanceSetting == Globals.PerformanceSettings.NoCaching)
                {
                    SiteLogBuffer = 1;
                }

                switch (SiteLogBuffer)
                {
                    case 0: //logging disabled
                        break;
                    case 1: //no buffering
                        switch (SiteLogStorage)
                        {
                            case "D": //database
                                _dataService.AddSiteLog(DateTime.Now,
                                                                   PortalId,
                                                                   UserId,
                                                                   objSecurity.InputFilter(Referrer, PortalSecurity.FilterFlag.NoScripting | PortalSecurity.FilterFlag.NoMarkup),
                                                                   objSecurity.InputFilter(URL, PortalSecurity.FilterFlag.NoScripting | PortalSecurity.FilterFlag.NoMarkup),
                                                                   objSecurity.InputFilter(UserAgent, PortalSecurity.FilterFlag.NoScripting | PortalSecurity.FilterFlag.NoMarkup),
                                                                   objSecurity.InputFilter(UserHostAddress, PortalSecurity.FilterFlag.NoScripting | PortalSecurity.FilterFlag.NoMarkup),
                                                                   objSecurity.InputFilter(UserHostName, PortalSecurity.FilterFlag.NoScripting | PortalSecurity.FilterFlag.NoMarkup),
                                                                   TabId,
                                                                   AffiliateId);
                                break;
                            case "F": //file system
                                W3CExtendedLog(DateTime.Now,
                                               PortalId,
                                               UserId,
                                               objSecurity.InputFilter(Referrer, PortalSecurity.FilterFlag.NoScripting | PortalSecurity.FilterFlag.NoMarkup),
                                               objSecurity.InputFilter(URL, PortalSecurity.FilterFlag.NoScripting | PortalSecurity.FilterFlag.NoMarkup),
                                               objSecurity.InputFilter(UserAgent, PortalSecurity.FilterFlag.NoScripting | PortalSecurity.FilterFlag.NoMarkup),
                                               objSecurity.InputFilter(UserHostAddress, PortalSecurity.FilterFlag.NoScripting | PortalSecurity.FilterFlag.NoMarkup),
                                               objSecurity.InputFilter(UserHostName, PortalSecurity.FilterFlag.NoScripting | PortalSecurity.FilterFlag.NoMarkup),
                                               TabId,
                                               AffiliateId);
                                break;
                        }
                        break;
                    default: //buffered logging
                        string key = "SiteLog" + PortalId;
                        var arrSiteLog = (ArrayList) DataCache.GetCache(key);
                        
						//get buffered site log records from the cache
						if (arrSiteLog == null)
                        {
                            arrSiteLog = new ArrayList();
                            DataCache.SetCache(key, arrSiteLog);
                        }
						
                        //create new sitelog object
                        var objSiteLog = new SiteLogInfo();
                        objSiteLog.DateTime = DateTime.Now;
                        objSiteLog.PortalId = PortalId;
                        objSiteLog.UserId = UserId;
                        objSiteLog.Referrer = objSecurity.InputFilter(Referrer, PortalSecurity.FilterFlag.NoScripting | PortalSecurity.FilterFlag.NoMarkup);
                        objSiteLog.URL = objSecurity.InputFilter(URL, PortalSecurity.FilterFlag.NoScripting | PortalSecurity.FilterFlag.NoMarkup);
                        objSiteLog.UserAgent = objSecurity.InputFilter(UserAgent, PortalSecurity.FilterFlag.NoScripting | PortalSecurity.FilterFlag.NoMarkup);
                        objSiteLog.UserHostAddress = objSecurity.InputFilter(UserHostAddress, PortalSecurity.FilterFlag.NoScripting | PortalSecurity.FilterFlag.NoMarkup);
                        objSiteLog.UserHostName = objSecurity.InputFilter(UserHostName, PortalSecurity.FilterFlag.NoScripting | PortalSecurity.FilterFlag.NoMarkup);
                        objSiteLog.TabId = TabId;
                        objSiteLog.AffiliateId = AffiliateId;

                        //add sitelog object to cache
                        arrSiteLog.Add(objSiteLog);

                        if (arrSiteLog.Count >= SiteLogBuffer)
                        {
							//create the buffered sitelog object
                            var objBufferedSiteLog = new BufferedSiteLog();
                            objBufferedSiteLog.SiteLogStorage = SiteLogStorage;
                            objBufferedSiteLog.SiteLog = arrSiteLog;

                            //clear the current sitelogs from the cache
                            DataCache.RemoveCache(key);

                            //process buffered sitelogs on a background thread
                            var objThread = new Thread(objBufferedSiteLog.AddSiteLog);
                            objThread.Start();
                        }
                        break;
                }
            }
            catch (Exception exc)
            {
                Logger.Error(exc);

            }
        }