Get Systemid in smppserver logger

.NET library for SMPP protocol
Post Reply
vineet
Posts: 13
Joined: Sat May 06, 2017 7:06 pm

Get Systemid in smppserver logger

Post by vineet » Tue Sep 05, 2017 8:30 pm

Hi is it possible to get systemid in smpp server global logger so the logs can be identified for each connected client.

Linzen
Posts: 1
Joined: Wed Oct 11, 2017 9:50 am

Re: Get Systemid in smppserver logger

Post by Linzen » Sun Oct 22, 2017 4:06 pm

I'd like to hear the answer to you question myself. It would be a neat feature to have.

alt
Site Admin
Posts: 727
Joined: Tue Apr 25, 2006 9:45 am

Re: Get Systemid in smppserver logger

Post by alt » Mon Nov 06, 2017 8:48 pm

Hi

I have added SmppClientBase.Name property that will be used as logger name.

When client binds with the server you can change the name as f.e.

Code: Select all

client.Name += "."+client.SystemID;
Please update to version 1.2.7 or higher.

vineet
Posts: 13
Joined: Sat May 06, 2017 7:06 pm

Re: Get Systemid in smppserver logger

Post by vineet » Fri Nov 17, 2017 9:50 am

Hi,
Still confused where to add this code. Please take a look at the existing code

Code: Select all

 public SMPPServer()
        {
            InitializeComponent();

            LogManager.SetLoggerFactory(loggerName => new SMPPLogger(loggerName)); //Need To Set The LoggerName For Each Connected Client?

            AppDomain.CurrentDomain.UnhandledException += (sender, args) =>
            {
                LogManager.GetLogger("AppDomain").Error("Unhandled Exception", (Exception)args.ExceptionObject);
            };

            LoggerObject = LogManager.GetLogger(GetType().Name);

            SMPPServerObject = new SmppServer();
            LicenseInfo.SetLicense(this.GetType().Assembly.GetManifestResourceStream(this.GetType(), "Inetlab.SMPP.license"));
            SMPPServerObject.evClientConnected += server_evClientConnected;
            SMPPServerObject.evClientDisconnected += server_evClientDisconnected;
            SMPPServerObject.evClientBind += server_evClientBind;
            SMPPServerObject.evClientSubmitSm += server_evClientSubmitSm;

            MessageComposerObject = new MessageComposer();
            MessageComposerObject.evFullMessageReceived += OnFullMessageReceived;
            MessageComposerObject.evFullMessageTimedout += OnFullMessageTimedout;
        }

Code: Select all

private void server_evClientBind(object sender, SmppServerClient client, Bind data)
        {
            AddToLog("INFO", string.Format("Client {0} Binding {1}:{2}", client.RemoteEndPoint, data.SystemId, data.Password), data.SystemId);

            data.Response.ChangeSystemId(Properties.Settings.Default.ServerName);

            tbl_customer_smpp_accounts SMPPAccount = ServerLayerObject.VerifySMPPLogin(data.SystemId);

            if(SMPPAccount == null)
            {
                data.Response.Status = CommandStatus.ESME_RINVSYSID;
                AddToLog("INFO", "Invalid System ID : " + data.SystemId, data.SystemId);
                return;
            }
            else
            {
                if (data.Password != SMPPAccount.SMPPPassword)
                {
                    data.Response.Status = CommandStatus.ESME_RINVPASWD;
                    AddToLog("INFO", "Invalid Password : " + data.Password, data.SystemId);
                    return;
                }
                else
                {
                    //GET IP ADDRESS OF CLIENT
                    string ClientIPAddress = IPAddress.Parse(((IPEndPoint)client.RemoteEndPoint).Address.ToString()).ToString();
                    string[] IPAddressList = SMPPAccount.IPAddress.Split(',');
                    foreach(string IPAddress in IPAddressList)
                    {
                        if (ClientIPAddress != IPAddress)
                        {
                            data.Response.Status = CommandStatus.ESME_RBINDFAIL;
                            AddToLog("INFO", "Invalid IP Address : " + ClientIPAddress, data.SystemId);
                            return;
                        }
                        else
                        {
                            //Setup Client Paramters
                            client.EnquireLinkInterval = TimeSpan.FromSeconds(60);
                            client.ConnectionTimeout = TimeSpan.FromSeconds(180);
                            data.Response.Status = CommandStatus.ESME_ROK;
                            ////Change number of threads that process received messages. Dafault is 3
                            client.WorkerThreads = 10;
                            ////Change receive buffer size for client socket
                            client.ReceiveBufferSize = 30 * 1024 * 1024;
                            ////Change send buffer size for client socket
                            client.SendBufferSize = 30 * 1024 * 1024;
                            ////Don't allow this client to send more than one message per second
                            //client.ReceiveSpeedLimit = SMPPAccount.SpeedLimit;
                            ////Set maximum number of unhandled messages in the receive queue for this client
                            //client.ReceiveQueueLimit = SMPPAccount.SpeedLimit;

                            client.evDeliverComplete += OnDeliverSmResp;

                            client.MapEncoding(DataCodings.Class1, new Inetlab.SMPP.Encodings.GSMPackedEncoding());

                            AddToLog("INFO", "Client Binded Sucessfully : " + data.SystemId, data.SystemId);
                        }
                    }
                }
            }
        }

alt
Site Admin
Posts: 727
Joined: Tue Apr 25, 2006 9:45 am

Re: Get Systemid in smppserver logger

Post by alt » Sun Nov 19, 2017 9:54 pm

Please try to change logger name for the client in this method:

Code: Select all

private void server_evClientBind(object sender, SmppServerClient client, Bind data)
        {
            client.Name += "."+data.SystemId;
           ...

vineet
Posts: 13
Joined: Sat May 06, 2017 7:06 pm

Re: Get Systemid in smppserver logger

Post by vineet » Wed Nov 22, 2017 6:09 am

Hi

Where can i get the SystemId in the looger class mentioned below

Code: Select all

public class SMPPLogger : ILog
    {
        private readonly string _loggerName;

        public SMPPLogger(string loggerName)
        {
            _loggerName = loggerName;
        }

        public string Name
        {
            get { return _loggerName; }
        }

        public void Error(object message, Exception ex)
        {
            if (ex != null)
            {
                AddToLog("ERROR", message + " Exception: " + ex.ToString());
            }
            else
            {
                AddToLog("ERROR" , message.ToString());
            }
        }

        public void Error(object message)
        {
            Error(message, null);
        }

        public void Warn(object message, Exception ex)
        {
            if (ex != null)
            {
                AddToLog("WARN" , message + " Exception: " + ex.ToString());
            }
            else
            {
                AddToLog("WARN" , message.ToString());
            }
        }

        public void Warn(object message)
        {
            Warn(message, null);
        }

        public void Info(object message)
        {
            AddToLog("INFO" , message.ToString());
        }

        public void Debug(object message)
        {
            AddToLog("DEBUG" , message.ToString());
        }

        public void Trace(object message)
        {
            AddToLog("TRACE", message.ToString());
        }

        public void Trace(object message, byte[] data)
        {
            AddToLog("TRACE" , message + " " + ByteArrayHelper.ToHexString(data));
        }

        public void AddToLog(string LogType, string LogDetails)
        {
            ServerLayer ServerLayerObject = new ServerLayer();
            ServerLayerObject.CreateNewLog(LogType, LogDetails);
        }
    }
Thanks

alt
Site Admin
Posts: 727
Joined: Tue Apr 25, 2006 9:45 am

Re: Get Systemid in smppserver logger

Post by alt » Mon Nov 27, 2017 10:13 pm

You can try to change logger property when client is binding.

Code: Select all

private void server_evClientBind(object sender, SmppServerClient client, Bind data)
{
    client.Logger = new SMPPLogger(data.SystemId);
   ...
}

Post Reply