diff --git a/Applications/ConsoleReferenceClient/ClientSamples.cs b/Applications/ConsoleReferenceClient/ClientSamples.cs index e21983b71..6f85b169f 100644 --- a/Applications/ConsoleReferenceClient/ClientSamples.cs +++ b/Applications/ConsoleReferenceClient/ClientSamples.cs @@ -104,7 +104,7 @@ public async Task ReadNodesAsync(ISession session, CancellationToken ct = defaul { if (session == null || !session.Connected) { - m_logger.LogInformation("Session not connected!"); + Console.WriteLine("Session not connected!"); return; } @@ -132,7 +132,7 @@ public async Task ReadNodesAsync(ISession session, CancellationToken ct = defaul }; // Read the node attributes - m_logger.LogInformation("Reading nodes..."); + Console.WriteLine("Reading nodes..."); // Call Read Service ReadResponse response = await session.ReadAsync( @@ -151,18 +151,15 @@ public async Task ReadNodesAsync(ISession session, CancellationToken ct = defaul // Display the results. foreach (DataValue result in resultsValues) { - m_logger.LogInformation( - "Read Value = {Value} , StatusCode = {StatusCode}", - result.Value, - result.StatusCode); + Console.WriteLine($"Read Value = {result.Value} , StatusCode = {result.StatusCode}"); } // Read Server NamespaceArray - m_logger.LogInformation("Reading Value of NamespaceArray node..."); + Console.WriteLine("Reading Value of NamespaceArray node..."); DataValue namespaceArray = await session.ReadValueAsync(Variables.Server_NamespaceArray, ct) .ConfigureAwait(false); // Display the result - m_logger.LogInformation("NamespaceArray Value = {NamespaceArray}", namespaceArray); + Console.WriteLine($"NamespaceArray Value = {namespaceArray}"); } catch (Exception ex) { @@ -178,7 +175,7 @@ public async Task WriteNodesAsync(ISession session, CancellationToken ct = defau { if (session == null || !session.Connected) { - m_logger.LogInformation("Session not connected!"); + Console.WriteLine("Session not connected!"); return; } @@ -215,7 +212,7 @@ public async Task WriteNodesAsync(ISession session, CancellationToken ct = defau nodesToWrite.Add(stringWriteVal); // Write the node attributes - m_logger.LogInformation("Writing nodes..."); + Console.WriteLine("Writing nodes..."); // Call Write Service WriteResponse response = await session.WriteAsync( @@ -230,11 +227,11 @@ public async Task WriteNodesAsync(ISession session, CancellationToken ct = defau m_validateResponse(results, nodesToWrite); // Display the results. - m_logger.LogInformation("Write Results :"); + Console.WriteLine("Write Results :"); foreach (StatusCode writeResult in results) { - m_logger.LogInformation(" {Result}", writeResult); + Console.WriteLine($" {writeResult}"); } } catch (Exception ex) @@ -251,7 +248,7 @@ public async Task BrowseAsync(ISession session, CancellationToken ct = default) { if (session == null || !session.Connected) { - m_logger.LogInformation("Session not connected!"); + Console.WriteLine("Session not connected!"); return; } @@ -270,19 +267,16 @@ public async Task BrowseAsync(ISession session, CancellationToken ct = default) NodeId nodeToBrowse = ObjectIds.Server; // Call Browse service - m_logger.LogInformation("Browsing {Count} node...", nodeToBrowse); + Console.WriteLine($"Browsing {nodeToBrowse} node..."); ReferenceDescriptionCollection browseResults = await browser.BrowseAsync(nodeToBrowse, ct).ConfigureAwait(false); // Display the results - m_logger.LogInformation("Browse returned {Count} results:", browseResults.Count); + Console.WriteLine($"Browse returned {browseResults.Count} results:"); foreach (ReferenceDescription result in browseResults) { - m_logger.LogInformation( - " DisplayName = {DisplayName}, NodeClass = {NodeClass}", - result.DisplayName.Text, - result.NodeClass); + Console.WriteLine($" DisplayName = {result.DisplayName.Text}, NodeClass = {result.NodeClass}"); } } catch (Exception ex) @@ -299,7 +293,7 @@ public async Task CallMethodAsync(ISession session, CancellationToken ct = defau { if (session == null || !session.Connected) { - m_logger.LogInformation("Session not connected!"); + Console.WriteLine("Session not connected!"); return; } @@ -317,7 +311,7 @@ public async Task CallMethodAsync(ISession session, CancellationToken ct = defau IList outputArguments = null; // Invoke Call service - m_logger.LogInformation("Calling UAMethod for method node id {NodeId} ...", methodId); + Console.WriteLine($"Calling UAMethod for node {methodId} ..."); outputArguments = await session.CallAsync( objectId, methodId, @@ -325,13 +319,11 @@ public async Task CallMethodAsync(ISession session, CancellationToken ct = defau inputArguments).ConfigureAwait(false); // Display results - m_logger.LogInformation( - "Method call returned {Count} output argument(s):", - outputArguments.Count); + Console.WriteLine($"Method call returned {outputArguments.Count} output argument(s):"); foreach (object outputArgument in outputArguments) { - m_logger.LogInformation(" OutputValue = {Value}", outputArgument); + Console.WriteLine($" OutputValue = {outputArgument}"); } } catch (Exception ex) @@ -350,7 +342,7 @@ public async Task EnableEventsAsync( { if (session == null || !session.Connected) { - m_logger.LogInformation("Session not connected!"); + Console.WriteLine("Session not connected!"); return; } @@ -368,7 +360,7 @@ public async Task EnableEventsAsync( IList outputArguments = null; // Invoke Call service - m_logger.LogInformation("Calling UAMethod for method node id {NodeId} ...", methodId); + Console.WriteLine($"Calling UAMethod for node {methodId} ..."); outputArguments = await session.CallAsync( objectId, methodId, @@ -376,13 +368,11 @@ public async Task EnableEventsAsync( inputArguments).ConfigureAwait(false); // Display results - m_logger.LogInformation( - "Method call returned {Count} output argument(s):", - outputArguments.Count); + Console.WriteLine($"Method call returned {outputArguments.Count} output argument(s):"); foreach (object outputArgument in outputArguments) { - m_logger.LogInformation(" OutputValue = {Value}", outputArgument); + Console.WriteLine($" OutputValue = {outputArgument}"); } } catch (Exception ex) @@ -404,7 +394,7 @@ public async Task SubscribeToDataChangesAsync( if (session == null || !session.Connected) { - m_logger.LogInformation("Session not connected!"); + Console.WriteLine("Session not connected!"); return isDurable; } diff --git a/Applications/ConsoleReferenceClient/Program.cs b/Applications/ConsoleReferenceClient/Program.cs index 444de137f..74faa9178 100644 --- a/Applications/ConsoleReferenceClient/Program.cs +++ b/Applications/ConsoleReferenceClient/Program.cs @@ -357,9 +357,7 @@ await application.DeleteApplicationInstanceCertificateAsync() if (reverseConnectUrlString != null) { // start the reverse connection manager - logger.LogInformation( - "Create reverse connection endpoint at {Url}.", - reverseConnectUrlString); + Console.WriteLine($"Create reverse connection endpoint at {reverseConnectUrlString}."); reverseConnectManager = new ReverseConnectManager(telemetry); reverseConnectManager.AddEndpoint(new Uri(reverseConnectUrlString)); reverseConnectManager.StartService(config); @@ -377,15 +375,11 @@ await application.DeleteApplicationInstanceCertificateAsync() { if (userpassword == null) { - logger.LogInformation( - "No password provided for user {Username}, using empty password.", - username); + Console.WriteLine($"No password provided for user {username}, using empty password."); } userIdentity = new UserIdentity(username, userpassword ?? ""u8); - logger.LogInformation( - "Connect with user identity for user {Username}", - username); + Console.WriteLine($"Connect with user identity for user {username}"); } // set user identity of type certificate @@ -410,15 +404,11 @@ CertificateIdentifier userCertificateIdentifier ct ).GetAwaiter().GetResult(); - logger.LogInformation( - "Connect with user certificate with Thumbprint {UserCertificateThumbprint}", - userCertificateThumbprint); + Console.WriteLine($"Connect with user certificate with Thumbprint {userCertificateThumbprint}"); } else { - logger.LogInformation( - "Failed to load user certificate with Thumbprint {UserCertificateThumbprint}", - userCertificateThumbprint); + Console.WriteLine($"Failed to load user certificate with Thumbprint {userCertificateThumbprint}"); } } @@ -470,7 +460,7 @@ CertificateIdentifier userCertificateIdentifier .ConfigureAwait(false); if (connected) { - logger.LogInformation("Connected! Ctrl-C to quit."); + Console.WriteLine("Connected! Ctrl-C to quit."); // enable subscription transfer uaClient.ReconnectPeriod = 1000; @@ -500,7 +490,7 @@ ReferenceDescriptionCollection referenceDescriptionsFromManagedBrowse if (browseall) { - logger.LogInformation("Browse the full address space."); + Console.WriteLine("Browse the full address space."); referenceDescriptions = await samples .BrowseFullAddressSpaceAsync(uaClient, Objects.RootFolder, ct: ct) .ConfigureAwait(false); @@ -519,7 +509,7 @@ .. referenceDescriptions if (managedbrowseall) { - logger.LogInformation("ManagedBrowse the full address space."); + Console.WriteLine("ManagedBrowse the full address space."); referenceDescriptionsFromManagedBrowse = await samples .ManagedBrowseFullAddressSpaceAsync( uaClient, @@ -631,9 +621,7 @@ await samples .ConfigureAwait(false); // Wait for DataChange notifications from MonitoredItems - logger.LogInformation( - "Subscribed to {Count} variables. Press Ctrl-C to exit.", - maxVariables); + Console.WriteLine($"Subscribed to {maxVariables} variables. Press Ctrl-C to exit."); // free unused memory uaClient.Session.NodeCache.Clear(); @@ -655,18 +643,11 @@ await samples .Session.ReadValueAsync( variableIterator.Current.NodeId, ct) .ConfigureAwait(false); - logger.LogInformation( - "Value of {NodeId} is {Value}", - variableIterator.Current.NodeId, - value - ); + Console.WriteLine($"Value of {variableIterator.Current.NodeId} is {value}"); } catch (Exception ex) { - logger.LogInformation(ex, - "Error reading value of {NodeId}", - variableIterator.Current.NodeId - ); + Console.WriteLine($"Error reading value of {variableIterator.Current.NodeId}: {ex.Message}"); } } else @@ -714,7 +695,7 @@ await samples.SubscribeToDataChangesAsync( enableDurableSubscriptions, ct).ConfigureAwait(false); - logger.LogInformation("Waiting..."); + Console.WriteLine("Waiting..."); // Wait for some DataChange notifications from MonitoredItems int waitCounters = 0; @@ -732,17 +713,14 @@ await samples.SubscribeToDataChangesAsync( if (waitCounters == closeSessionTime && uaClient.Session.SubscriptionCount == 1) { - logger.LogInformation( - "Closing Session (CurrentTime: {Time})", - DateTime.Now.ToLongTimeString()); + Console.WriteLine($"Closing Session (CurrentTime: {DateTime.Now.ToLongTimeString()})"); await uaClient.Session.CloseAsync(closeChannel: false, ct: ct) .ConfigureAwait(false); } if (waitCounters == restartSessionTime) { - logger.LogInformation("Restarting Session (CurrentTime: {Time})", - DateTime.Now.ToLongTimeString()); + Console.WriteLine($"Restarting Session (CurrentTime: {DateTime.Now.ToLongTimeString()})"); await uaClient .DurableSubscriptionTransferAsync( serverUrl.ToString(), @@ -764,23 +742,22 @@ await uaClient } } - logger.LogInformation("Client disconnected."); + Console.WriteLine("Client disconnected."); await uaClient.DisconnectAsync(leakChannels, ct).ConfigureAwait(false); } else { - logger.LogInformation( - "Could not connect to server! Retry in 10 seconds or Ctrl-C to quit."); + Console.WriteLine("Could not connect to server! Retry in 10 seconds or Ctrl-C to quit."); quit = quitEvent.WaitOne(Math.Min(10_000, waitTime)); } } while (!quit); - logger.LogInformation("Client stopped."); + Console.WriteLine("Client stopped."); } catch (Exception ex) { - logger.LogInformation("{Error}", ex.Message); + Console.WriteLine($"{ex.Message}"); } finally { diff --git a/Applications/ConsoleReferenceClient/UAClient.cs b/Applications/ConsoleReferenceClient/UAClient.cs index ae7d1874a..044b242d1 100644 --- a/Applications/ConsoleReferenceClient/UAClient.cs +++ b/Applications/ConsoleReferenceClient/UAClient.cs @@ -159,16 +159,14 @@ public async Task DurableSubscriptionTransferAsync( subscriptions != null && Session != null) { - m_logger.LogInformation( - "Transferring {Count} subscriptions from old session to new session...", - subscriptions.Count); + Console.WriteLine($"Transferring {subscriptions.Count} subscriptions from old session to new session..."); success = await Session.TransferSubscriptionsAsync( subscriptions, true, ct).ConfigureAwait(false); if (success) { - m_logger.LogInformation("Subscriptions transferred."); + Console.WriteLine("Subscriptions transferred."); } } @@ -200,7 +198,7 @@ public async Task ConnectAsync( { if (Session != null && Session.Connected) { - m_logger.LogInformation("Session already connected!"); + Console.WriteLine("Session already connected!"); } else { @@ -208,7 +206,7 @@ public async Task ConnectAsync( EndpointDescription endpointDescription = null; if (m_reverseConnectManager != null) { - m_logger.LogInformation("Waiting for reverse connection to.... {Url}", serverUrl); + Console.WriteLine($"Waiting for reverse connection to.... {serverUrl}"); do { using var cts = new CancellationTokenSource(30_000); @@ -227,7 +225,7 @@ public async Task ConnectAsync( } if (endpointDescription == null) { - m_logger.LogInformation("Discover reverse connection endpoints...."); + Console.WriteLine("Discover reverse connection endpoints...."); endpointDescription = await CoreClientUtils.SelectEndpointAsync( m_configuration, connection, @@ -241,7 +239,7 @@ public async Task ConnectAsync( } else { - m_logger.LogInformation("Connecting to... {Url}", serverUrl); + Console.WriteLine($"Connecting to... {serverUrl}"); endpointDescription = await CoreClientUtils.SelectEndpointAsync( m_configuration, serverUrl, @@ -299,9 +297,7 @@ public async Task ConnectAsync( } // Session created successfully. - m_logger.LogInformation( - "New Session Created with SessionName = {SessionName}", - Session.SessionName); + Console.WriteLine($"New Session Created with SessionName = {Session.SessionName}"); } return true; @@ -309,7 +305,7 @@ public async Task ConnectAsync( catch (Exception ex) { // Log Error - m_logger.LogInformation("Create Session Error : {Message}", ex.Message); + Console.WriteLine($"Create Session Error : {ex.Message}"); return false; } } @@ -324,7 +320,7 @@ public async Task DisconnectAsync(bool leaveChannelOpen = false, CancellationTok { if (Session != null) { - m_logger.LogInformation("Disconnecting..."); + Console.WriteLine("Disconnecting..."); lock (m_lock) { @@ -344,11 +340,11 @@ public async Task DisconnectAsync(bool leaveChannelOpen = false, CancellationTok Session = null; // Log Session Disconnected event - m_logger.LogInformation("Session Disconnected."); + Console.WriteLine("Session Disconnected."); } else { - m_logger.LogInformation("Session not created!"); + Console.WriteLine("Session not created!"); } } catch (Exception ex) diff --git a/Applications/ConsoleReferenceServer/Program.cs b/Applications/ConsoleReferenceServer/Program.cs index 36302202e..f6fcedf82 100644 --- a/Applications/ConsoleReferenceServer/Program.cs +++ b/Applications/ConsoleReferenceServer/Program.cs @@ -128,13 +128,13 @@ public static async Task Main(string[] args) }; // load the server configuration, validate certificates - logger.LogInformation("Loading configuration from config section {Name}.", configSectionName); + Console.WriteLine($"Loading configuration from {configSectionName}."); await server.LoadAsync(applicationName, configSectionName).ConfigureAwait(false); // use the shadow config to map the config to an externally accessible location if (shadowConfig) { - logger.LogInformation("Using shadow configuration."); + Console.WriteLine("Using shadow configuration."); string shadowPath = Directory .GetParent( Path.GetDirectoryName( @@ -148,10 +148,10 @@ public static async Task Main(string[] args) ); if (!File.Exists(shadowFilePath)) { - logger.LogInformation("Create a copy of the config in the shadow location."); + Console.WriteLine("Create a copy of the config in the shadow location."); File.Copy(server.Configuration.SourceFilePath, shadowFilePath, true); } - logger.LogInformation("Reloading configuration from shadow location {FilePath}.", shadowFilePath); + Console.WriteLine($"Reloading configuration from shadow location {shadowFilePath}."); await server .LoadAsync(applicationName, Path.Combine(shadowPath, configSectionName)) .ConfigureAwait(false); @@ -161,7 +161,7 @@ await server telemetry.ConfigureLogging(server.Configuration, applicationName, logConsole, fileLog, appLog, LogLevel.Information); // check or renew the certificate - logger.LogInformation("Check the certificate."); + Console.WriteLine("Check the certificate."); await server.CheckCertificateAsync(renewCertificate).ConfigureAwait(false); // Create and add the node managers @@ -170,12 +170,12 @@ await server // enable provisioning mode if requested if (provisioningMode) { - logger.LogInformation("Enabling provisioning mode."); + Console.WriteLine("Enabling provisioning mode."); Servers.Utils.EnableProvisioningMode(server.Server); // Auto-accept is required in provisioning mode if (!autoAccept) { - logger.LogInformation("Auto-accept enabled for provisioning mode."); + Console.WriteLine("Auto-accept enabled for provisioning mode."); autoAccept = true; server.AutoAccept = autoAccept; } @@ -188,7 +188,7 @@ await server } // start the server - logger.LogInformation("Start the server."); + Console.WriteLine("Start the server."); await server.StartAsync().ConfigureAwait(false); // setup reverse connect if specified @@ -196,7 +196,7 @@ await server { try { - logger.LogInformation("Adding reverse connection to {Url}.", reverseConnectUrlString); + Console.WriteLine($"Adding reverse connection to {reverseConnectUrlString}."); var reverseConnectUrl = new Uri(reverseConnectUrlString); server.Server.AddReverseConnection(reverseConnectUrl); } @@ -212,13 +212,13 @@ await server // Apply custom settings for CTT testing if (cttMode) { - logger.LogInformation("Apply settings for CTT."); + Console.WriteLine("Apply settings for CTT."); // start Alarms and other settings for CTT test await Servers.Utils.ApplyCTTModeAsync(Console.Out, server.Server) .ConfigureAwait(false); } - logger.LogInformation("Server started. Press Ctrl-C to exit..."); + Console.WriteLine("Server started. Press Ctrl-C to exit..."); // wait for timeout or Ctrl-C var quitCTS = new CancellationTokenSource(); @@ -226,14 +226,14 @@ await Servers.Utils.ApplyCTTModeAsync(Console.Out, server.Server) bool ctrlc = quitEvent.WaitOne(timeout); // stop server. May have to wait for clients to disconnect. - logger.LogInformation("Server stopped. Waiting for exit..."); + Console.WriteLine("Server stopped. Waiting for exit..."); await server.StopAsync().ConfigureAwait(false); return (int)ExitCode.Ok; } catch (ErrorExitException eee) { - logger.LogInformation("The application exits with error: {ExitMessage}", eee.Message); + Console.WriteLine($"The application exits with error: {eee.Message}"); return (int)eee.ExitCode; } } diff --git a/Applications/ConsoleReferenceServer/UAServer.cs b/Applications/ConsoleReferenceServer/UAServer.cs index 0efc70477..e1d54bcb9 100644 --- a/Applications/ConsoleReferenceServer/UAServer.cs +++ b/Applications/ConsoleReferenceServer/UAServer.cs @@ -174,7 +174,7 @@ public async Task StartAsync() // print endpoint info foreach (string endpoint in Application.Server.GetEndpoints().Select(e => e.EndpointUrl).Distinct()) { - m_logger.LogInformation("{Endpoint}", endpoint); + Console.WriteLine(endpoint); } // start the status thread