本文整理汇总了C#中Logger.LogMessage方法的典型用法代码示例。如果您正苦于以下问题:C# Logger.LogMessage方法的具体用法?C# Logger.LogMessage怎么用?C# Logger.LogMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Logger
的用法示例。
在下文中一共展示了Logger.LogMessage方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
/// <summary>
/// Server's main loop implementation.
/// </summary>
/// <param name="log"> The Logger instance to be used.</param>
public void Run(Logger log)
{
try{
try
{
_server = new TcpListener(IPAddress.Loopback, portNumber);
_server.Start();
}
catch (ArgumentOutOfRangeException argex)
{
MessageBox.Show(@"The port number inserted is not valid!", @"ERROR");
_server = null;
throw argex;
}
catch (SocketException sock)
{
MessageBox.Show(@"The specified port is already in use by another server!",
@"ERROR");
_server = null;
throw sock;
}
// Define the callback method - which will be called whenever a client request ends;
AsyncCallback onAcceptCallback = null;
int nseconds = 10;
onAcceptCallback = delegate(IAsyncResult ar)
{
log.IncrementRequests();
TcpClient socket = null;
EndPoint clientEndPoint = null;
try
{
// Asynchronously accept an incoming connection attempt
// and create a new TcpClient to handle remote host communication
socket = _server.EndAcceptTcpClient(ar);
// Begin an async operation: to accept an incoming connection attempt
_server.BeginAcceptTcpClient(onAcceptCallback, _server);
// Process the accepted connection.
/////////////////////////////////////////////////////////////////////
log.LogMessage("Listener - Processing the accepted connection...");
socket.LingerState = new LingerOption(true, nseconds);
clientEndPoint = socket.Client.RemoteEndPoint;
log.LogMessage(String.Format("Listener - Connection established with {0}.",
clientEndPoint));
// Instantiate protocol handler and associate it to the current TCP connection
var protocolHandler = new Program.Handler(socket.GetStream(), log);
// Synchronously process request made through the connection
protocolHandler.Run();
Utils.ShowInfo(Store.Instance, log.Writer);
/////////////////////////////////////////////////////////////////////
}
catch (SocketException sockex)
{
Console.WriteLine("***socket exception occurred: {0}", sockex.Message);
}
catch (ObjectDisposedException)
{
//
// This exception happens when the listener socket is closed.
// So, we just ignore it!
//
}
log.LogMessage(socket != null && socket.Connected
? String.Format("Listener - Time left for socket to be disconnected: {0} seconds.",
socket.Client.LingerState.LingerTime)
: String.Format("Listener - Connection closed with {0}.", clientEndPoint));
};
// Begins an asynchronous operation to accept an incoming connection attempt.
_server.BeginAcceptTcpClient(onAcceptCallback, null);
}
finally
{
if (_server == null)
{
log.LogMessage("listener - ERROR: Server is undefined!");
}
// else
// {
// log.LogMessage("Listener - Ending.");
// srv.Stop();
// }
}
}