Make tracing better
This commit is contained in:
Родитель
25c830620b
Коммит
6397a9c39f
|
@ -17,7 +17,8 @@
|
|||
*.dll
|
||||
*.so
|
||||
*.pdb
|
||||
/src/GatewayApp.NetCore/Logs
|
||||
*.der
|
||||
*.exe
|
||||
/src/out
|
||||
/src/Logs
|
||||
|
||||
|
|
|
@ -22,6 +22,19 @@ namespace Opc.Ua.Publisher
|
|||
Configuration.ClientConfiguration = new ClientConfiguration();
|
||||
Configuration.ServerConfiguration = new ServerConfiguration();
|
||||
|
||||
// enable logging
|
||||
Configuration.TraceConfiguration = new TraceConfiguration();
|
||||
Configuration.TraceConfiguration.TraceMasks = Utils.TraceMasks.Error | Utils.TraceMasks.Security | Utils.TraceMasks.StackTrace | Utils.TraceMasks.StartStop;
|
||||
if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("_GW_LOGP")))
|
||||
{
|
||||
Configuration.TraceConfiguration.OutputFilePath = Environment.GetEnvironmentVariable("_GW_LOGP");
|
||||
}
|
||||
else
|
||||
{
|
||||
Configuration.TraceConfiguration.OutputFilePath = "./Logs/" + Configuration.ApplicationName + ".log.txt";
|
||||
}
|
||||
Configuration.TraceConfiguration.ApplySettings();
|
||||
|
||||
if (Configuration.SecurityConfiguration == null)
|
||||
{
|
||||
Configuration.SecurityConfiguration = new SecurityConfiguration();
|
||||
|
@ -161,12 +174,6 @@ namespace Opc.Ua.Publisher
|
|||
newPolicy.SecurityPolicyUri = SecurityPolicies.Basic128Rsa15;
|
||||
Configuration.ServerConfiguration.SecurityPolicies.Add(newPolicy);
|
||||
|
||||
// enable logging
|
||||
Configuration.TraceConfiguration = new TraceConfiguration();
|
||||
Configuration.TraceConfiguration.TraceMasks = Utils.TraceMasks.Error | Utils.TraceMasks.Security | Utils.TraceMasks.StackTrace | Utils.TraceMasks.StartStop;
|
||||
Configuration.TraceConfiguration.OutputFilePath = "./Logs/" + Configuration.ApplicationName + ".log.txt";
|
||||
Configuration.TraceConfiguration.ApplySettings();
|
||||
|
||||
// the OperationTimeout should be twice the minimum value for PublishingInterval * KeepAliveCount, so set to 120s
|
||||
Configuration.TransportQuotas.OperationTimeout = 120000;
|
||||
|
||||
|
|
|
@ -29,35 +29,56 @@ namespace Opc.Ua.Publisher
|
|||
/// </summary>
|
||||
public static void Trace(string message, params object[] args)
|
||||
{
|
||||
Utils.Trace(message, args);
|
||||
Console.WriteLine(message, args);
|
||||
Utils.Trace(Utils.TraceMasks.Error, message, args);
|
||||
Console.WriteLine(DateTime.Now.ToString() + ": " + message, args);
|
||||
}
|
||||
|
||||
public static void Trace(int traceMask, string format, params object[] args)
|
||||
{
|
||||
Utils.Trace(traceMask, format, args);
|
||||
Console.WriteLine(format, args);
|
||||
Console.WriteLine(DateTime.Now.ToString() + ": " + format, args);
|
||||
}
|
||||
|
||||
public static void Trace(Exception e, string format, params object[] args)
|
||||
{
|
||||
Utils.Trace(e, format, args);
|
||||
Console.WriteLine(e.ToString());
|
||||
Console.WriteLine(format, args);
|
||||
Console.WriteLine(DateTime.Now.ToString() + ": " + e.Message.ToString());
|
||||
Console.WriteLine(DateTime.Now.ToString() + ": " + format, args);
|
||||
}
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
if ((args.Length == 0) || string.IsNullOrEmpty(args[0]))
|
||||
{
|
||||
Console.WriteLine("Please specify an application name as argument!");
|
||||
Trace("Please specify an application name as argument!");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
Trace("Publisher is starting up...");
|
||||
}
|
||||
|
||||
m_applicationName = args[0];
|
||||
string ownerConnectionString = string.Empty;
|
||||
ModuleConfiguration moduleConfiguration = new ModuleConfiguration(m_applicationName);
|
||||
m_configuration = moduleConfiguration.Configuration;
|
||||
m_configuration.CertificateValidator.CertificateValidation += new CertificateValidationEventHandler(CertificateValidator_CertificateValidation);
|
||||
|
||||
// start our server interface
|
||||
try
|
||||
{
|
||||
Trace("Starting server on endpoint " + m_configuration.ServerConfiguration.BaseAddresses[0].ToString() + "...");
|
||||
m_server.Start(m_configuration);
|
||||
Trace("Server started.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Trace("Starting server failed with: " + ex.Message);
|
||||
}
|
||||
|
||||
// check if we also received an owner connection string
|
||||
string ownerConnectionString = string.Empty;
|
||||
if ((args.Length > 1) && !string.IsNullOrEmpty(args[1]))
|
||||
{
|
||||
ownerConnectionString = args[1];
|
||||
|
@ -118,17 +139,6 @@ namespace Opc.Ua.Publisher
|
|||
Trace("Device connection string not found in secure store.");
|
||||
}
|
||||
|
||||
ModuleConfiguration moduleConfiguration = new ModuleConfiguration(m_applicationName);
|
||||
m_configuration = moduleConfiguration.Configuration;
|
||||
m_configuration.CertificateValidator.CertificateValidation += new CertificateValidationEventHandler(CertificateValidator_CertificateValidation);
|
||||
|
||||
// update log configuration, if available
|
||||
if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("_GW_LOGP")))
|
||||
{
|
||||
m_configuration.TraceConfiguration.OutputFilePath = Environment.GetEnvironmentVariable("_GW_LOGP");
|
||||
m_configuration.TraceConfiguration.ApplySettings();
|
||||
}
|
||||
|
||||
// get a list of persisted endpoint URLs and create a session for each.
|
||||
try
|
||||
{
|
||||
|
@ -156,19 +166,7 @@ namespace Opc.Ua.Publisher
|
|||
}
|
||||
}
|
||||
|
||||
// start the server
|
||||
try
|
||||
{
|
||||
Trace("Starting server on endpoint " + m_configuration.ServerConfiguration.BaseAddresses[0].ToString() + "...");
|
||||
m_server.Start(m_configuration);
|
||||
Trace("Server started.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Trace("Starting server failed with: " + ex.Message);
|
||||
}
|
||||
|
||||
// connect to servers
|
||||
// connect to the other servers
|
||||
Trace("Attemping to connect to servers...");
|
||||
try
|
||||
{
|
||||
|
@ -204,7 +202,7 @@ namespace Opc.Ua.Publisher
|
|||
}
|
||||
}
|
||||
|
||||
Console.WriteLine("Publisher is running. Press enter to quit.");
|
||||
Trace("Publisher is running. Press enter to quit.");
|
||||
Console.ReadLine();
|
||||
|
||||
foreach (Session session in m_sessions)
|
||||
|
@ -217,6 +215,11 @@ namespace Opc.Ua.Publisher
|
|||
m_deviceClient.CloseAsync().Wait();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Trace(e, "Unhandled exception in Publisher, exiting!");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Connects to a single OPC UA Server's endpoint
|
||||
|
|
Загрузка…
Ссылка в новой задаче