Skip to content

Commit a9c8ffa

Browse files
committed
update
1 parent 754a9f9 commit a9c8ffa

File tree

23 files changed

+103
-186
lines changed

23 files changed

+103
-186
lines changed

Samples/ClientControls.Net4/Common/Client/ConnectServerCtrl.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
using System.Threading;
3434
using System.Threading.Tasks;
3535
using System.Windows.Forms;
36+
using Microsoft.Extensions.Logging;
3637
using Opc.Ua.Client.ComplexTypes;
3738

3839
namespace Opc.Ua.Client.Controls
@@ -56,6 +57,7 @@ public ConnectServerCtrl()
5657

5758
#region Private Fields
5859
private ITelemetryContext m_telemetry;
60+
private ILogger m_logger;
5961
private ApplicationConfiguration m_configuration;
6062
private ISession m_session;
6163
private SessionReconnectHandler m_reconnectHandler;
@@ -301,6 +303,7 @@ private async Task<ISession> ConnectInternalAsync(
301303
CancellationToken ct = default)
302304
{
303305
m_telemetry = telemetry;
306+
m_logger = telemetry.CreateLogger<ConnectServerCtrl>();
304307

305308
// disconnect from existing session.
306309
await InternalDisconnectAsync(ct);
@@ -334,7 +337,7 @@ private async Task<ISession> ConnectInternalAsync(
334337
catch (Exception e)
335338
{
336339
UpdateStatus(true, DateTime.Now, "Connected, failed to load complex type system.");
337-
Utils.LogWarning(e, "Failed to load complex type system.");
340+
m_logger.LogWarning(e, "Failed to load complex type system.");
338341
}
339342

340343
// return the new session.
@@ -353,6 +356,7 @@ private async Task<ISession> ConnectInternalAsync(
353356
CancellationToken ct = default)
354357
{
355358
m_telemetry = telemetry;
359+
m_logger = telemetry.CreateLogger<ConnectServerCtrl>();
356360

357361
// disconnect from existing session.
358362
await InternalDisconnectAsync(ct);
@@ -382,7 +386,7 @@ private async Task<ISession> ConnectInternalAsync(
382386
catch (Exception e)
383387
{
384388
UpdateStatus(true, DateTime.Now, "Connected, failed to load complex type system.");
385-
Utils.LogError(e, "Failed to load complex type system.");
389+
m_logger.LogError(e, "Failed to load complex type system.");
386390
}
387391

388392
// return the new session.

Samples/ClientControls.Net4/Common/DiscoverServerDlg.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ private async Task<string[]> GetEndpointsAsync(string hostName, CancellationToke
120120
configuration.OperationTimeout = 20000;
121121

122122
// Connect to the local discovery server and find the available servers.
123-
using (DiscoveryClient client = await DiscoveryClient.CreateAsync(new Uri(Utils.Format("opc.tcp://{0}:4840", hostName)), configuration, m_telemetry))
123+
using (DiscoveryClient client = await DiscoveryClient.CreateAsync(new Uri(Utils.Format("opc.tcp://{0}:4840", hostName)), configuration, m_telemetry, DiagnosticsMasks.None, ct))
124124
{
125125
ApplicationDescriptionCollection servers = await client.FindServersAsync(null, ct);
126126

Samples/Controls.Net4/Sessions/BrowseTreeCtrl.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
using Opc.Ua.Client.Controls;
4141
using System.Threading.Tasks;
4242
using System.Threading;
43+
using Microsoft.Extensions.Logging;
4344

4445
namespace Opc.Ua.Sample.Controls
4546
{
@@ -58,6 +59,7 @@ public BrowseTreeCtrl()
5859
private Browser m_browser;
5960
private ISession m_session;
6061
private ITelemetryContext m_telemetry;
62+
private ILogger m_logger;
6163
private NodeId m_rootId;
6264
private AttributeListCtrl m_AttributesCtrl;
6365
private bool m_allowPick;
@@ -175,6 +177,7 @@ public async Task SetRootAsync(Browser browser, NodeId rootId, ISession session,
175177
m_browser = browser;
176178
m_session = session;
177179
m_telemetry = telemetry;
180+
m_logger = telemetry.CreateLogger<BrowseTreeCtrl>();
178181

179182
if (m_browser != null)
180183
{
@@ -660,47 +663,47 @@ private async Task AddReferencesAsync(TreeNode parent, ReferenceDescriptionColle
660663
{
661664
if (reference.ReferenceTypeId.IsNullNodeId)
662665
{
663-
Utils.Trace("Reference {0} has null reference type id", reference.DisplayName);
666+
m_logger.LogDebug("Reference {0} has null reference type id", reference.DisplayName);
664667
continue;
665668
}
666669

667670
ReferenceTypeNode typeNode = await m_session.NodeCache.FindAsync(reference.ReferenceTypeId, ct) as ReferenceTypeNode;
668671
if (typeNode == null)
669672
{
670-
Utils.Trace("Reference {0} has invalid reference type id.", reference.DisplayName);
673+
m_logger.LogDebug("Reference {0} has invalid reference type id.", reference.DisplayName);
671674
continue;
672675
}
673676

674677
if (m_browser.BrowseDirection == BrowseDirection.Forward && !reference.IsForward
675678
|| m_browser.BrowseDirection == BrowseDirection.Inverse && reference.IsForward)
676679
{
677-
Utils.Trace("Reference's IsForward value is: {0}, but the browse direction is: {1}; for reference {2}", reference.IsForward, m_browser.BrowseDirection, reference.DisplayName);
680+
m_logger.LogDebug("Reference's IsForward value is: {0}, but the browse direction is: {1}; for reference {2}", reference.IsForward, m_browser.BrowseDirection, reference.DisplayName);
678681
continue;
679682
}
680683

681684
if (reference.NodeId == null || reference.NodeId.IsNull)
682685
{
683-
Utils.Trace("The node id of the reference {0} is NULL.", reference.DisplayName);
686+
m_logger.LogDebug("The node id of the reference {0} is NULL.", reference.DisplayName);
684687
continue;
685688
}
686689

687690
if (reference.BrowseName == null || reference.BrowseName.Name == null)
688691
{
689-
Utils.Trace("Browse name is empty for reference {0}", reference.DisplayName);
692+
m_logger.LogDebug("Browse name is empty for reference {0}", reference.DisplayName);
690693
continue;
691694
}
692695

693696
if (!Enum.IsDefined(typeof(Opc.Ua.NodeClass), reference.NodeClass) || reference.NodeClass == NodeClass.Unspecified)
694697
{
695-
Utils.Trace("Node class is an unknown or unspecified value, for reference {0}", reference.DisplayName);
698+
m_logger.LogDebug("Node class is an unknown or unspecified value, for reference {0}", reference.DisplayName);
696699
continue;
697700
}
698701

699702
if (m_browser.NodeClassMask != 0 && m_browser.NodeClassMask != 255)
700703
{
701704
if (reference.TypeDefinition == null || reference.TypeDefinition.IsNull)
702705
{
703-
Utils.Trace("Type definition is null for reference {0}", reference.DisplayName);
706+
m_logger.LogDebug("Type definition is null for reference {0}", reference.DisplayName);
704707
continue;
705708
}
706709
}
@@ -760,7 +763,7 @@ private async Task<TreeNode> FindReferenceTypeContainerAsync(TreeNode parent, Re
760763

761764
if (reference.ReferenceTypeId.IsNullNodeId)
762765
{
763-
Utils.Trace("NULL reference type id, for reference: {0}", reference.DisplayName);
766+
m_logger.LogDebug("NULL reference type id, for reference: {0}", reference.DisplayName);
764767
return null;
765768
}
766769

@@ -807,7 +810,7 @@ private async Task<TreeNode> FindReferenceTypeContainerAsync(TreeNode parent, Re
807810
return AddNode(parent, typeNode.NodeId, text, icon);
808811
}
809812

810-
Utils.Trace("Reference type id not found for: {0}", reference.ReferenceTypeId);
813+
m_logger.LogDebug("Reference type id not found for: {0}", reference.ReferenceTypeId);
811814

812815
return null;
813816
}

Samples/Controls.Net4/Subscriptions/SubscriptionDlg.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
using System.Threading;
3939
using System.Threading.Tasks;
4040
using System.Windows.Forms;
41+
using Microsoft.Extensions.Logging;
4142
using Opc.Ua.Client;
4243
using Opc.Ua.Client.Controls;
4344

@@ -59,6 +60,7 @@ public SubscriptionDlg()
5960

6061
#region Private Fields
6162
private ITelemetryContext m_telemetry;
63+
private ILogger m_logger;
6264
private Subscription m_subscription;
6365
private NotificationEventHandler m_SessionNotification;
6466
private SubscriptionStateChangedEventHandler m_SubscriptionStateChanged;
@@ -75,6 +77,7 @@ public async Task<Subscription> NewAsync(Session session, ITelemetryContext tele
7577
if (session == null) throw new ArgumentNullException(nameof(session));
7678

7779
m_telemetry = telemetry;
80+
m_logger = telemetry.CreateLogger<SubscriptionDlg>();
7881

7982
Subscription subscription = new Subscription(session.DefaultSubscription);
8083

@@ -89,7 +92,7 @@ public async Task<Subscription> NewAsync(Session session, ITelemetryContext tele
8992
Subscription duplicateSubscription = session.Subscriptions.FirstOrDefault(s => s.Id != 0 && s.Id.Equals(subscription.Id) && s != subscription);
9093
if (duplicateSubscription != null)
9194
{
92-
Utils.Trace("Duplicate subscription was created with the id: {0}", duplicateSubscription.Id);
95+
m_logger.LogWarning("Duplicate subscription was created with the id: {0}", duplicateSubscription.Id);
9396

9497
DialogResult result = MessageBox.Show("Duplicate subscription was created with the id: " + duplicateSubscription.Id + ". Do you want to keep it?", "Warning", MessageBoxButtons.YesNo);
9598
if (result == System.Windows.Forms.DialogResult.No)

Samples/ReferenceServer/Program.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ static void Main()
8181
loggerConfiguration.WriteTo.Debug(restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Warning);
8282
#pragma warning restore CA1305 // Specify IFormatProvider
8383
#endif
84-
SerilogTraceLogger.Create(loggerConfiguration, config);
85-
84+
8685
// check the application certificate.
8786
bool certOk = application.CheckApplicationInstanceCertificatesAsync(false).AsTask().Result;
8887
if (!certOk)

Samples/ReferenceServer/Reference Server.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@
8484
</Compile>
8585
<Compile Include="Program.cs" />
8686
<Compile Include="Properties\AssemblyInfo.cs" />
87-
<Compile Include="SerilogTraceLogger.cs" />
8887
<Compile Include="ReferenceServerUtils.cs" />
8988
<Content Include="Resources\OPCFoundation.jpg" />
9089
<EmbeddedResource Include="MonitoredItemEventLogDlg.resx">

Samples/ReferenceServer/ReferenceServerUtils.cs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
* http://opcfoundation.org/License/MIT/1.00/
2828
* ======================================================================*/
2929

30+
using Microsoft.Extensions.Logging;
3031
using Opc.Ua;
3132
using Opc.Ua.Server;
3233
using System;
@@ -363,13 +364,14 @@ public static uint CreateError(
363364
uint code,
364365
OperationContext context,
365366
DiagnosticInfoCollection diagnosticInfos,
366-
int index)
367+
int index,
368+
ILogger logger)
367369
{
368370
ServiceResult error = new ServiceResult(code);
369371

370372
if ((context.DiagnosticsMask & DiagnosticsMasks.OperationAll) != 0)
371373
{
372-
diagnosticInfos[index] = new DiagnosticInfo(error, context.DiagnosticsMask, false, context.StringTable);
374+
diagnosticInfos[index] = new DiagnosticInfo(error, context.DiagnosticsMask, false, context.StringTable, logger);
373375
}
374376

375377
return error.Code;
@@ -382,14 +384,15 @@ public static bool CreateError(
382384
uint code,
383385
StatusCodeCollection results,
384386
DiagnosticInfoCollection diagnosticInfos,
385-
OperationContext context)
387+
OperationContext context,
388+
ILogger logger)
386389
{
387390
ServiceResult error = new ServiceResult(code);
388391
results.Add(error.Code);
389392

390393
if ((context.DiagnosticsMask & DiagnosticsMasks.OperationAll) != 0)
391394
{
392-
diagnosticInfos.Add(new DiagnosticInfo(error, context.DiagnosticsMask, false, context.StringTable));
395+
diagnosticInfos.Add(new DiagnosticInfo(error, context.DiagnosticsMask, false, context.StringTable, logger));
393396
return true;
394397
}
395398

@@ -404,14 +407,15 @@ public static bool CreateError(
404407
StatusCodeCollection results,
405408
DiagnosticInfoCollection diagnosticInfos,
406409
int index,
407-
OperationContext context)
410+
OperationContext context,
411+
ILogger logger)
408412
{
409413
ServiceResult error = new ServiceResult(code);
410414
results[index] = error.Code;
411415

412416
if ((context.DiagnosticsMask & DiagnosticsMasks.OperationAll) != 0)
413417
{
414-
diagnosticInfos[index] = new DiagnosticInfo(error, context.DiagnosticsMask, false, context.StringTable);
418+
diagnosticInfos[index] = new DiagnosticInfo(error, context.DiagnosticsMask, false, context.StringTable, logger);
415419
return true;
416420
}
417421

@@ -439,7 +443,8 @@ public static void CreateSuccess(
439443
/// </summary>
440444
public static DiagnosticInfoCollection CreateDiagnosticInfoCollection(
441445
OperationContext context,
442-
IList<ServiceResult> errors)
446+
IList<ServiceResult> errors,
447+
ILogger logger)
443448
{
444449
// all done if no diagnostics requested.
445450
if ((context.DiagnosticsMask & DiagnosticsMasks.OperationAll) == 0)
@@ -454,7 +459,7 @@ public static DiagnosticInfoCollection CreateDiagnosticInfoCollection(
454459
{
455460
if (ServiceResult.IsBad(error))
456461
{
457-
results.Add(new DiagnosticInfo(error, context.DiagnosticsMask, false, context.StringTable));
462+
results.Add(new DiagnosticInfo(error, context.DiagnosticsMask, false, context.StringTable, logger));
458463
}
459464
else
460465
{
@@ -471,6 +476,7 @@ public static DiagnosticInfoCollection CreateDiagnosticInfoCollection(
471476
public static StatusCodeCollection CreateStatusCodeCollection(
472477
OperationContext context,
473478
IList<ServiceResult> errors,
479+
ILogger logger,
474480
out DiagnosticInfoCollection diagnosticInfos)
475481
{
476482
diagnosticInfos = null;
@@ -494,7 +500,7 @@ public static StatusCodeCollection CreateStatusCodeCollection(
494500
// only generate diagnostics if errors exist.
495501
if (noErrors)
496502
{
497-
diagnosticInfos = CreateDiagnosticInfoCollection(context, errors);
503+
diagnosticInfos = CreateDiagnosticInfoCollection(context, errors, logger);
498504
}
499505

500506
return results;
@@ -510,7 +516,8 @@ public static StatusCodeCollection CreateStatusCodeCollection(
510516
public static DiagnosticInfo CreateDiagnosticInfo(
511517
IServerInternal server,
512518
OperationContext context,
513-
ServiceResult error)
519+
ServiceResult error,
520+
ILogger logger)
514521
{
515522
if (error == null)
516523
{
@@ -528,7 +535,8 @@ public static DiagnosticInfo CreateDiagnosticInfo(
528535
translatedError,
529536
context.DiagnosticsMask,
530537
false,
531-
context.StringTable);
538+
context.StringTable,
539+
logger);
532540

533541
return diagnosticInfo;
534542
}

0 commit comments

Comments
 (0)