-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
a13b1c1
commit 4ee4e8a
Showing
16 changed files
with
462 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,67 @@ | ||
// Licensed under the BSD license | ||
// See the LICENSE file in the project root for more information | ||
|
||
using System; | ||
using System.ComponentModel; | ||
|
||
namespace NLog.Targets.Syslog.Settings | ||
{ | ||
/// <summary>Message build configuration</summary> | ||
public class MessageBuilderConfig | ||
public class MessageBuilderConfig : NotifyPropertyChanged, IDisposable | ||
{ | ||
private Facility facility; | ||
private RfcNumber rfc; | ||
private Rfc3164Config rfc3164; | ||
private readonly PropertyChangedEventHandler rfc3164PropsChanged; | ||
private Rfc5424Config rfc5424; | ||
private readonly PropertyChangedEventHandler rfc5424PropsChanged; | ||
|
||
/// <summary>The Syslog facility to log from (its name e.g. local0 or local7)</summary> | ||
public Facility Facility { get; set; } | ||
public Facility Facility | ||
{ | ||
get { return facility; } | ||
set { SetProperty(ref facility, value); } | ||
} | ||
|
||
/// <summary>The Syslog protocol RFC to be followed</summary> | ||
public RfcNumber Rfc { get; set; } | ||
public RfcNumber Rfc | ||
{ | ||
get { return rfc; } | ||
set { SetProperty(ref rfc, value); } | ||
} | ||
|
||
/// <summary>RFC 3164 related fields</summary> | ||
public Rfc3164Config Rfc3164 { get; set; } | ||
public Rfc3164Config Rfc3164 | ||
{ | ||
get { return rfc3164; } | ||
set { SetProperty(ref rfc3164, value); } | ||
} | ||
|
||
/// <summary>RFC 5424 related fields</summary> | ||
public Rfc5424Config Rfc5424 { get; set; } | ||
public Rfc5424Config Rfc5424 | ||
{ | ||
get { return rfc5424; } | ||
set { SetProperty(ref rfc5424, value); } | ||
} | ||
|
||
/// <summary>Builds a new instance of the MessageBuilderConfig class</summary> | ||
public MessageBuilderConfig() | ||
{ | ||
Rfc = RfcNumber.Rfc5424; | ||
Rfc3164 = new Rfc3164Config(); | ||
Rfc5424 = new Rfc5424Config(); | ||
rfc = RfcNumber.Rfc5424; | ||
rfc3164 = new Rfc3164Config(); | ||
rfc3164PropsChanged = (sender, args) => OnPropertyChanged(nameof(Rfc3164)); | ||
rfc3164.PropertyChanged += rfc3164PropsChanged; | ||
|
||
rfc5424 = new Rfc5424Config(); | ||
rfc5424PropsChanged = (sender, args) => OnPropertyChanged(nameof(Rfc5424)); | ||
rfc5424.PropertyChanged += rfc5424PropsChanged; | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
rfc3164.PropertyChanged -= rfc3164PropsChanged; | ||
rfc5424.PropertyChanged -= rfc5424PropsChanged; | ||
rfc5424.Dispose(); | ||
} | ||
} | ||
} |
45 changes: 39 additions & 6 deletions
45
src/NLog.Targets.Syslog/Settings/MessageTransmitterConfig.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,58 @@ | ||
// Licensed under the BSD license | ||
// See the LICENSE file in the project root for more information | ||
|
||
using System; | ||
using System.ComponentModel; | ||
|
||
namespace NLog.Targets.Syslog.Settings | ||
{ | ||
/// <summary>Message transmission configuration</summary> | ||
public class MessageTransmitterConfig | ||
public class MessageTransmitterConfig : NotifyPropertyChanged, IDisposable | ||
{ | ||
private ProtocolType protocol; | ||
private UdpConfig udp; | ||
private readonly PropertyChangedEventHandler udpPropsChanged; | ||
private TcpConfig tcp; | ||
private readonly PropertyChangedEventHandler tcpPropsChanged; | ||
|
||
/// <summary>The Syslog server protocol</summary> | ||
public ProtocolType Protocol { get; set; } | ||
public ProtocolType Protocol | ||
{ | ||
get { return protocol; } | ||
set { SetProperty(ref protocol, value); } | ||
} | ||
|
||
/// <summary>UDP related fields</summary> | ||
public UdpConfig Udp { get; set; } | ||
public UdpConfig Udp | ||
{ | ||
get { return udp; } | ||
set { SetProperty(ref udp, value); } | ||
} | ||
|
||
/// <summary>TCP related fields</summary> | ||
public TcpConfig Tcp { get; set; } | ||
public TcpConfig Tcp | ||
{ | ||
get { return tcp; } | ||
set { SetProperty(ref tcp, value); } | ||
} | ||
|
||
/// <summary>Builds a new instance of the MessageTransmitterConfig class</summary> | ||
public MessageTransmitterConfig() | ||
{ | ||
Udp = new UdpConfig(); | ||
Tcp = new TcpConfig(); | ||
udp = new UdpConfig(); | ||
udpPropsChanged = (sender, args) => OnPropertyChanged(nameof(Udp)); | ||
udp.PropertyChanged += udpPropsChanged; | ||
|
||
tcp = new TcpConfig(); | ||
tcpPropsChanged = (sender, args) => OnPropertyChanged(nameof(Tcp)); | ||
tcp.PropertyChanged += tcpPropsChanged; | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
udp.PropertyChanged -= udpPropsChanged; | ||
tcp.PropertyChanged -= tcpPropsChanged; | ||
tcp.Dispose(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System.Collections.Specialized; | ||
using System.ComponentModel; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace NLog.Targets.Syslog.Settings | ||
{ | ||
/// <summary>Implementation of <see cref="INotifyPropertyChanged" /> to simplify config settings</summary> | ||
public abstract class NotifyPropertyChanged : INotifyPropertyChanged | ||
{ | ||
/// <summary>Multicast event for property change notifications</summary> | ||
public event PropertyChangedEventHandler PropertyChanged; | ||
|
||
protected bool SetProperty<T>(ref T oldValue, T newValue, [CallerMemberName] string propertyName = null) | ||
{ | ||
if (Equals(oldValue, newValue)) | ||
{ | ||
return false; | ||
} | ||
|
||
oldValue = newValue; | ||
OnPropertyChanged(propertyName); | ||
return true; | ||
} | ||
|
||
protected void OnPropertyChanged(string propertyName) | ||
{ | ||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); | ||
} | ||
|
||
protected NotifyCollectionChangedEventHandler CollectionChangedFactory(PropertyChangedEventHandler onElemPropsChanged) | ||
{ | ||
return (sender, eventArgs) => | ||
{ | ||
if (eventArgs.NewItems != null) | ||
foreach (INotifyPropertyChanged item in eventArgs.NewItems) | ||
item.PropertyChanged += onElemPropsChanged; | ||
|
||
if (eventArgs.OldItems != null) | ||
foreach (INotifyPropertyChanged item in eventArgs.OldItems) | ||
item.PropertyChanged -= onElemPropsChanged; | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.