Beispiel #1
0
        // logs session infos to logfile (at each mail); if you want to change
        // the log record format, this is the place to do it, just change the
        // "cols.Add" to include the columns you want and there you'll go :-)
        private void logSession()
        {
            // check if already logged
            if (this._lastMsgID == this._msgCount)
            {
                return;
            }
            this._lastMsgID = this._msgCount;

            // check if we got some data
            if (string.IsNullOrEmpty(this._heloStr))
            {
                this._heloStr = "-no-helo-";
            }
            if (string.IsNullOrEmpty(this._mailFrom))
            {
                this._mailFrom = "-no-from-";
            }
            // if (0 == this._rcptTo.Count) return;

            // build the log array
            List <string> cols = new List <string>();

            // current date/time
            cols.Add(DateTime.UtcNow.ToString("u"));

            // start date, session ID, client IP, helo
            cols.Add(this._startDate.ToString("u"));
            cols.Add(this._sessionID.ToString());
            cols.Add(this._clientIP);
            cols.Add(this._heloStr);

            // mail from
            if (!string.IsNullOrEmpty(this._mailFrom))
            {
                cols.Add(this._mailFrom);
            }
            else
            {
                cols.Add("");
            }

            // rcpt to
            if (this._rcptTo.Count > 0)
            {
                cols.Add(this._rcptTo.Count.ToString());
                cols.Add(string.Join(",", this._rcptTo));
            }
            else
            {
                cols.Add("0");
                cols.Add("-no-rcpt-");
            }

            // message # and message file name (if any)
            cols.Add(this._msgCount.ToString());
            if (!string.IsNullOrEmpty(this._msgFile))
            {
                cols.Add(this._msgFile);
            }
            else
            {
                cols.Add("-no-file-");
            }

            // dns listing
            if (!string.IsNullOrEmpty(this._dnsListType))
            {
                cols.Add(this._dnsListType);
                cols.Add(this._dnsListName);
                cols.Add(this._dnsListValue);
            }
            else
            {
                cols.Add("-not-listed-");
                cols.Add("-none-");
                cols.Add("0.0.0.0");
            }

            // early talker
            if (this._earlyTalker)
            {
                cols.Add("1");
            }
            else
            {
                cols.Add("0");
            }

            // noop/vrfy/err
            cols.Add(this._noopCount.ToString());
            cols.Add(this._vrfyCount.ToString());
            cols.Add(this._errCount.ToString());

            // builds and logs the record
            //string logRec = string.Join("|", cols);
            //AppGlobals.logSession("{0}", logRec);

            // builds the log record format string
            StringBuilder logFmt = new StringBuilder("{0}");

            for (int i = 1; i < cols.Count; i++)
            {
                logFmt.Append("|{" + i + "}");
            }

            // log the record
            AppGlobals.logSession(logFmt.ToString(), cols.ToArray <string>());
        }