Skip to content
This repository was archived by the owner on Feb 12, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/NLog.Targets.Syslog/MessageSend/SocketInitialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,31 @@
using System.Runtime.InteropServices;
using NLog.Targets.Syslog.Settings;

using Debug = System.Diagnostics.Debug;

namespace NLog.Targets.Syslog.MessageSend
{
internal abstract class SocketInitialization
{
public static SocketInitialization ForCurrentOs()
{
string rt = RuntimeInformation.OSDescription;

bool isMac = RuntimeInformation.IsOSPlatform(OSPlatform.OSX);

Debug.WriteLine($"===== NLog.Targets.Syslog detected OS: {rt}");
Debug.WriteLine($"isMac: {isMac}");

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
return new SocketInitializationForWindows();
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))

if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
||
rt.ToLower().Contains("linux"))
{
return new SocketInitializationForLinux();
}

return new SocketInitializationForOsx();
}

Expand Down
60 changes: 30 additions & 30 deletions src/NLog.Targets.Syslog/Policies/PolicySet.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
// Licensed under the BSD license
// See the LICENSE file in the project root for more information
using System.Collections.Generic;
namespace NLog.Targets.Syslog.Policies
{
internal abstract class PolicySet
{
private readonly List<IBasicPolicy<string, string>> policies;
protected PolicySet()
{
policies = new List<IBasicPolicy<string, string>>();
}
protected void AddPolicies(IEnumerable<IBasicPolicy<string, string>> policiesToAdd)
{
policies.AddRange(policiesToAdd);
}
public string Apply(string s)
{
var afterApplication = s;
foreach (var policy in policies)
if (policy.IsApplicable())
afterApplication = policy.Apply(afterApplication);
return afterApplication;
}
}
// Licensed under the BSD license
// See the LICENSE file in the project root for more information

using System.Collections.Generic;

namespace NLog.Targets.Syslog.Policies
{
internal abstract class PolicySet
{
private readonly List<IBasicPolicy<string, string>> policies;

protected PolicySet()
{
policies = new List<IBasicPolicy<string, string>>();
}

protected void AddPolicies(IEnumerable<IBasicPolicy<string, string>> policiesToAdd)
{
policies.AddRange(policiesToAdd);
}

public string Apply(string s)
{
var afterApplication = s;
foreach (var policy in policies)
if (policy.IsApplicable())
afterApplication = policy.Apply(afterApplication);
return afterApplication;
}
}
}
172 changes: 86 additions & 86 deletions src/NLog.Targets.Syslog/Settings/MessageBuilderConfig.cs
Original file line number Diff line number Diff line change
@@ -1,87 +1,87 @@
// Licensed under the BSD license
// See the LICENSE file in the project root for more information
using System;
using System.ComponentModel;
using NLog.Config;
namespace NLog.Targets.Syslog.Settings
{
/// <inheritdoc cref="NotifyPropertyChanged" />
/// <inheritdoc cref="IDisposable" />
/// <summary>Message build configuration</summary>
[NLogConfigurationItem]
public class MessageBuilderConfig : NotifyPropertyChanged, IDisposable
{
private Facility facility;
private LogLevelSeverityConfig perLogLevelSeverity;
private readonly PropertyChangedEventHandler perLogLevelSeverityPropsChanged;
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 => facility;
set => SetProperty(ref facility, value);
}
/// <summary>Log level Syslog severity related fields</summary>
public LogLevelSeverityConfig PerLogLevelSeverity
{
get => perLogLevelSeverity;
set => SetProperty(ref perLogLevelSeverity, value);
}
/// <summary>The Syslog protocol RFC to be followed</summary>
public RfcNumber Rfc
{
get => rfc;
set => SetProperty(ref rfc, value);
}
/// <summary>RFC 3164 related fields</summary>
public Rfc3164Config Rfc3164
{
get => rfc3164;
set => SetProperty(ref rfc3164, value);
}
/// <summary>RFC 5424 related fields</summary>
public Rfc5424Config Rfc5424
{
get => rfc5424;
set => SetProperty(ref rfc5424, value);
}
/// <summary>Builds a new instance of the MessageBuilderConfig class</summary>
public MessageBuilderConfig()
{
perLogLevelSeverity = new LogLevelSeverityConfig();
perLogLevelSeverityPropsChanged = (sender, args) => OnPropertyChanged(nameof(PerLogLevelSeverity));
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;
}
/// <inheritdoc />
/// <summary>Disposes the instance</summary>
public void Dispose()
{
perLogLevelSeverity.PropertyChanged -= perLogLevelSeverityPropsChanged;
rfc3164.PropertyChanged -= rfc3164PropsChanged;
rfc5424.PropertyChanged -= rfc5424PropsChanged;
rfc5424.Dispose();
}
}
// Licensed under the BSD license
// See the LICENSE file in the project root for more information

using System;
using System.ComponentModel;
using NLog.Config;

namespace NLog.Targets.Syslog.Settings
{
/// <inheritdoc cref="NotifyPropertyChanged" />
/// <inheritdoc cref="IDisposable" />
/// <summary>Message build configuration</summary>
[NLogConfigurationItem]
public class MessageBuilderConfig : NotifyPropertyChanged, IDisposable
{
private Facility facility;
private LogLevelSeverityConfig perLogLevelSeverity;
private readonly PropertyChangedEventHandler perLogLevelSeverityPropsChanged;
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 => facility;
set => SetProperty(ref facility, value);
}

/// <summary>Log level Syslog severity related fields</summary>
public LogLevelSeverityConfig PerLogLevelSeverity
{
get => perLogLevelSeverity;
set => SetProperty(ref perLogLevelSeverity, value);
}

/// <summary>The Syslog protocol RFC to be followed</summary>
public RfcNumber Rfc
{
get => rfc;
set => SetProperty(ref rfc, value);
}

/// <summary>RFC 3164 related fields</summary>
public Rfc3164Config Rfc3164
{
get => rfc3164;
set => SetProperty(ref rfc3164, value);
}

/// <summary>RFC 5424 related fields</summary>
public Rfc5424Config Rfc5424
{
get => rfc5424;
set => SetProperty(ref rfc5424, value);
}

/// <summary>Builds a new instance of the MessageBuilderConfig class</summary>
public MessageBuilderConfig()
{
perLogLevelSeverity = new LogLevelSeverityConfig();
perLogLevelSeverityPropsChanged = (sender, args) => OnPropertyChanged(nameof(PerLogLevelSeverity));

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;
}

/// <inheritdoc />
/// <summary>Disposes the instance</summary>
public void Dispose()
{
perLogLevelSeverity.PropertyChanged -= perLogLevelSeverityPropsChanged;
rfc3164.PropertyChanged -= rfc3164PropsChanged;
rfc5424.PropertyChanged -= rfc5424PropsChanged;
rfc5424.Dispose();
}
}
}
Loading