Skip to content

Commit 290eeff

Browse files
authored
Refactor logger fields to static/readonly for safety for tests and examples (#1693)
Updated logger fields to be static or readonly across the codebase, enhancing thread safety and code clarity. Also applied minor formatting fixes and improved immutability in test classes. Aligns with best practices for logger usage.
1 parent ccd97ca commit 290eeff

16 files changed

Lines changed: 19 additions & 19 deletions

File tree

examples/Softphone/Signalling/SIPTransportManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class SIPTransportManager
3434
private static string HOMER_SERVER_ADDRESS = null; //"192.168.11.49";
3535
private static int HOMER_SERVER_PORT = 9060;
3636

37-
private ILogger logger = SIPSorcery.LogFactory.CreateLogger<SIPTransportManager>();
37+
private static ILogger logger = SIPSorcery.LogFactory.CreateLogger<SIPTransportManager>();
3838

3939
private XmlNode m_sipSocketsNode = SIPSoftPhoneState.SIPSocketsNode; // Optional XML node that can be used to configure the SIP channels used with the SIP transport layer.
4040

examples/Softphone/Signalling/STUNClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace SIPSorcery.SoftPhone
2424
{
2525
public class SoftphoneSTUNClient
2626
{
27-
private ILogger logger = SIPSorcery.LogFactory.CreateLogger<SoftphoneSTUNClient>();
27+
private static ILogger logger = SIPSorcery.LogFactory.CreateLogger<SoftphoneSTUNClient>();
2828

2929
private Timer updateTimer;
3030

@@ -95,4 +95,4 @@ private IPAddress GetPublicIPAddress()
9595
}
9696
}
9797
}
98-
}
98+
}

examples/WebRTCExamples/RtspToWebRTCAudioAndVideo/WebSocketSignalingServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace RtspToWebRtcRestreamer
1515
{
1616
internal class WebSocketSignalingServer : IDisposable
1717
{
18-
private ILogger<WebSocketSignalingServer> _logger;
18+
private static readonly ILogger<WebSocketSignalingServer> _logger;
1919
private int _port;
2020
private WebSocketServer _ws;
2121
private FFmpegListener _ffmpegListener;

examples/WebRTCLightningExamples/WebRTCLightningGetStarted/Services/LightningClientFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public interface ILightningClientFactory
3939

4040
public class LightningClientFactory : ILightningClientFactory
4141
{
42-
private ILogger _logger;
42+
private readonly ILogger _logger;
4343
private IConfiguration _config;
4444

4545
private readonly string _lndUrl;

examples/WebRTCLightningExamples/WebRTCLightningGetStarted/Services/LightningService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public interface ILightningService
4242

4343
public class LightningService : ILightningService
4444
{
45-
private ILogger _logger;
45+
private readonly ILogger _logger;
4646

4747
private readonly ILightningClientFactory _lightningClientFactory;
4848

test/integration/net/ICE/MockTurnServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace SIPSorcery.Net.IntegrationTests
2525
{
2626
public class MockTurnServer : IDisposable
2727
{
28-
private readonly ILogger logger = LogFactory.CreateLogger<MockTurnServer>();
28+
private static readonly ILogger logger = LogFactory.CreateLogger<MockTurnServer>();
2929

3030
private int _listenPort = STUNConstants.DEFAULT_STUN_PORT;
3131
private IPAddress _listenAddress = IPAddress.Loopback;

test/unit/net/RTP/ReorderBufferUnitTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ internal class DatetimeProvider : IDateTime
1313
[Trait("Category", "unit")]
1414
public class ReorderBufferUnitTest
1515
{
16-
private ILogger logger = null;
16+
private readonly ILogger logger;
1717

1818
public ReorderBufferUnitTest(Xunit.Abstractions.ITestOutputHelper output)
1919
{

test/unit/net/SCTP/SctpAssociationUnitTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace SIPSorcery.Net.UnitTests
2727
{
2828
public class SctpAssociationUnitTest
2929
{
30-
private ILogger logger = null;
30+
private readonly ILogger logger;
3131

3232
public SctpAssociationUnitTest(Xunit.Abstractions.ITestOutputHelper output)
3333
{

test/unit/net/SCTP/SctpChunkUnitTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace SIPSorcery.Net.UnitTests
2323
{
2424
public class SctpChunkUnitTest
2525
{
26-
private ILogger logger = null;
26+
private readonly ILogger logger;
2727

2828
public SctpChunkUnitTest(Xunit.Abstractions.ITestOutputHelper output)
2929
{

test/unit/net/SCTP/SctpDataReceiverUnitTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//-----------------------------------------------------------------------------
1+
//-----------------------------------------------------------------------------
22
// Filename: SctpDataReceiverUnitTest.cs
33
//
44
// Description: Unit tests for the SctpDataReceiver class.
@@ -22,7 +22,7 @@ namespace SIPSorcery.Net.UnitTests
2222
{
2323
public class SctpDataReceiverUnitTest
2424
{
25-
private ILogger logger = null;
25+
private readonly ILogger logger;
2626

2727
public SctpDataReceiverUnitTest(Xunit.Abstractions.ITestOutputHelper output)
2828
{

0 commit comments

Comments
 (0)