This repository has been archived by the owner on Mar 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable programmatic configuration of Loggly c-sharp client
- Loading branch information
Showing
7 changed files
with
130 additions
and
13 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
41 changes: 41 additions & 0 deletions
41
src/Serilog.Sinks.Loggly/Sinks/Loggly/LogglyConfigAdapter.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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System; | ||
using Loggly.Config; | ||
|
||
namespace Serilog.Sinks.Loggly | ||
{ | ||
class LogglyConfigAdapter | ||
{ | ||
public void ConfigureLogglyClient(LogglyConfiguration logglyConfiguration) | ||
{ | ||
var config = LogglyConfig.Instance; | ||
|
||
if (!string.IsNullOrWhiteSpace(logglyConfiguration.ApplicationName)) | ||
config.ApplicationName = logglyConfiguration.ApplicationName; | ||
|
||
if (string.IsNullOrWhiteSpace(logglyConfiguration.CustomerToken)) | ||
throw new ArgumentNullException("CustomerToken", "CustomerToken is required"); | ||
|
||
config.CustomerToken = logglyConfiguration.CustomerToken; | ||
config.IsEnabled = logglyConfiguration.IsEnabled; | ||
|
||
foreach (var tag in logglyConfiguration.Tags) | ||
{ | ||
config.TagConfig.Tags.Add(tag); | ||
} | ||
|
||
config.ThrowExceptions = logglyConfiguration.ThrowExceptions; | ||
|
||
if (logglyConfiguration.LogTransport != TransportProtocol.Https) | ||
config.Transport.LogTransport = (LogTransport)Enum.Parse(typeof(LogTransport), logglyConfiguration.LogTransport.ToString()); | ||
|
||
if (!string.IsNullOrWhiteSpace(logglyConfiguration.EndpointHostName)) | ||
config.Transport.EndpointHostname = logglyConfiguration.EndpointHostName; | ||
|
||
if (logglyConfiguration.EndpointPort > 0 && logglyConfiguration.EndpointPort < ushort.MaxValue) | ||
config.Transport.EndpointPort = logglyConfiguration.EndpointPort; | ||
|
||
config.Transport.IsOmitTimestamp = logglyConfiguration.OmitTimestamp; | ||
config.Transport = config.Transport.GetCoercedToValidConfig(); | ||
} | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
src/Serilog.Sinks.Loggly/Sinks/Loggly/LogglyConfiguration.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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Serilog.Sinks.Loggly | ||
{ | ||
public class LogglyConfiguration | ||
{ | ||
public string ApplicationName { get; set; } | ||
public string CustomerToken { get; set; } | ||
public List<string> Tags { get; set; } | ||
public bool IsEnabled { get; set; } = true; | ||
public bool ThrowExceptions { get; set; } | ||
|
||
/// <summary> | ||
/// Defaults to Https | ||
/// </summary> | ||
public TransportProtocol LogTransport { get; set; } | ||
|
||
/// <summary> | ||
/// Defaults to logs-01.loggly.com | ||
/// </summary> | ||
public string EndpointHostName { get; set; } | ||
|
||
/// <summary> | ||
/// Defaults to default port for selected LogTransport. | ||
/// E.g. https is 443, SyslogTcp/-Udp is 514 and SyslogSecure is 6514. | ||
/// </summary> | ||
public int EndpointPort { get; set; } | ||
|
||
/// <summary> | ||
/// Defines if timestamp should automatically be added to the json body when using Https | ||
/// </summary> | ||
public bool OmitTimestamp { get; set; } | ||
} | ||
|
||
public enum TransportProtocol | ||
{ | ||
/// <summary> | ||
/// Https. | ||
/// </summary> | ||
Https, | ||
|
||
/// <summary> | ||
/// SyslogSecure. | ||
/// </summary> | ||
SyslogSecure, | ||
|
||
/// <summary> | ||
/// SyslogUdp. | ||
/// </summary> | ||
SyslogUdp, | ||
|
||
/// <summary> | ||
/// SyslogTcp. | ||
/// </summary> | ||
SyslogTcp, | ||
} | ||
} |
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