Skip to content
This repository has been archived by the owner on Jun 1, 2024. It is now read-only.

Commit

Permalink
Moved work on 2.0 to separate repos
Browse files Browse the repository at this point in the history
  • Loading branch information
Mpdreamz committed Mar 2, 2015
1 parent 20563c6 commit 010af25
Show file tree
Hide file tree
Showing 23 changed files with 767 additions and 584 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ _TeamCity*
# NCrunch
_NCrunch_*
.*crunch*.local.xml
*.ncrunch*

# MightyMoose
*.mm.*
Expand Down
2 changes: 1 addition & 1 deletion assets/CommonAssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Reflection;

[assembly: AssemblyVersion("0.0.0")]
[assembly: AssemblyFileVersion("0..0")]
[assembly: AssemblyFileVersion("0.0.0")]
[assembly: AssemblyInformationalVersion("0.")]
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Net.Configuration;
using Elasticsearch.Net.Connection;
using Elasticsearch.Net.Serialization;
using Serilog.Configuration;
using Serilog.Core;
using Serilog.Events;
using Serilog.Sinks.ElasticSearch;

Expand All @@ -29,147 +29,6 @@ namespace Serilog
/// </summary>
public static class LoggerConfigurationElasticSearchExtensions
{
/// <summary>
/// Adds a sink that writes log events as documents to an ElasticSearch index.
/// This works great with the Kibana web interface when using the default settings.
/// Make sure to add a template to ElasticSearch like the one found here:
/// https://gist.github.com/mivano/9688328
/// </summary>
/// <param name="loggerConfiguration">The logger configuration.</param>
/// <param name="indexFormat">The index format where the events are send to. It defaults to the logstash index per day format. It uses a String.Format using the DateTime.UtcNow parameter.</param>
/// <param name="node">The URI to the node where ElasticSearch is running. When null, will fall back to http://localhost:9200</param>
/// <param name="connectionTimeOutInMilliseconds">The connection time out in milliseconds. Default value is 5000.</param>
/// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
/// <param name="batchPostingLimit">The maximum number of events to post in a single batch.</param>
/// <param name="period">The time to wait between checking for event batches.</param>
/// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
/// <param name="serializer">When passing a serializer unknown object will be serialized to object instead of relying on their ToString representation</param>
/// <returns>
/// Logger configuration, allowing configuration to continue.
/// </returns>
/// <exception cref="System.ArgumentNullException">loggerConfiguration</exception>
/// <exception cref="ArgumentNullException">A required parameter is null.</exception>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("Please use Elasticsearch(ElasticsearchSinkOptions options), this method might not expose all options and should be removed in the next Serilog major release")]
public static LoggerConfiguration ElasticSearch(
this LoggerSinkConfiguration loggerConfiguration,
string indexFormat = ElasticsearchSink.DefaultIndexFormat,
Uri node = null,
int connectionTimeOutInMilliseconds = ElasticsearchSink.DefaultConnectionTimeout,
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
int batchPostingLimit = ElasticsearchSink.DefaultBatchPostingLimit,
TimeSpan? period = null,
IFormatProvider formatProvider = null,
IElasticsearchSerializer serializer = null
)
{
if (node == null)
node = new Uri("http://localhost:9200");

return Elasticsearch(loggerConfiguration, new ElasticsearchSinkOptions(new [] { node })
{
Serializer = serializer,
FormatProvider = formatProvider,
IndexFormat = indexFormat,
ModifyConnectionSetttings = s => s.SetTimeout(connectionTimeOutInMilliseconds),
BatchPostingLimit = batchPostingLimit,
Period = period,
MinimumLogEventLevel = restrictedToMinimumLevel
});
}

/// <summary>
/// Adds a sink that writes log events as documents to an ElasticSearch index.
/// This works great with the Kibana web interface when using the default settings.
/// Make sure to add a template to ElasticSearch like the one found here:
/// https://gist.github.com/mivano/9688328
/// </summary>
/// <param name="loggerConfiguration">The logger configuration.</param>
/// <param name="nodes">The node URIs of the Elasticsearch cluster.</param>
/// <param name="indexFormat">The index format where the events are send to. It defaults to the logstash index per day format. It uses a String.Format using the DateTime.UtcNow parameter.</param>
/// <param name="connectionTimeOutInMilliseconds">The connection time out in milliseconds. Default value is 5000.</param>
/// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
/// <param name="batchPostingLimit">The maximum number of events to post in a single batch.</param>
/// <param name="period">The time to wait between checking for event batches.</param>
/// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
/// <param name="serializer">When passing a serializer unknown object will be serialized to object instead of relying on their ToString representation</param>
/// <returns>
/// Logger configuration, allowing configuration to continue.
/// </returns>
/// <exception cref="System.ArgumentNullException">loggerConfiguration</exception>
/// <exception cref="ArgumentNullException">A required parameter is null.</exception>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("Please use Elasticsearch(ElasticsearchSinkOptions options), this method might not expose all options and should be removed in the next Serilog major release")]
public static LoggerConfiguration ElasticSearch(
this LoggerSinkConfiguration loggerConfiguration,
IEnumerable<Uri> nodes,
string indexFormat = ElasticsearchSink.DefaultIndexFormat,
int connectionTimeOutInMilliseconds = ElasticsearchSink.DefaultConnectionTimeout,
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
int batchPostingLimit = ElasticsearchSink.DefaultBatchPostingLimit,
TimeSpan? period = null,
IFormatProvider formatProvider = null,
IElasticsearchSerializer serializer = null
)
{
return Elasticsearch(loggerConfiguration, new ElasticsearchSinkOptions(nodes)
{
Serializer = serializer,
FormatProvider = formatProvider,
IndexFormat = indexFormat,
ModifyConnectionSetttings = s => s.SetTimeout(connectionTimeOutInMilliseconds),
BatchPostingLimit = batchPostingLimit,
Period = period,
MinimumLogEventLevel = restrictedToMinimumLevel
});
}

/// <summary>
/// Adds a sink that writes log events as documents to an ElasticSearch index.
/// This works great with the Kibana web interface when using the default settings.
/// Make sure to add a template to ElasticSearch like the one found here:
/// https://gist.github.com/mivano/9688328
/// </summary>
/// <param name="loggerConfiguration">The logger configuration.</param>
/// <param name="connectionConfiguration">The configuration to use for connecting to the Elasticsearch cluster.</param>
/// <param name="indexFormat">The index format where the events are send to. It defaults to the logstash index per day format. It uses a String.Format using the DateTime.UtcNow parameter.</param>
/// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
/// <param name="batchPostingLimit">The maximum number of events to post in a single batch.</param>
/// <param name="period">The time to wait between checking for event batches.</param>
/// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
/// <param name="serializer">When passing a serializer unknown object will be serialized to object instead of relying on their ToString representation</param>
/// <returns>
/// Logger configuration, allowing configuration to continue.
/// </returns>
/// <exception cref="System.ArgumentNullException">loggerConfiguration</exception>
/// <exception cref="ArgumentNullException">A required parameter is null.</exception>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("Please use Elasticsearch(ElasticsearchSinkOptions options), this method might not expose all options and should be removed in the next Serilog major release")]
public static LoggerConfiguration ElasticSearch(
this LoggerSinkConfiguration loggerConfiguration,
ConnectionConfiguration connectionConfiguration,
string indexFormat = ElasticsearchSink.DefaultIndexFormat,
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
int batchPostingLimit = ElasticsearchSink.DefaultBatchPostingLimit,
TimeSpan? period = null,
IFormatProvider formatProvider = null,
IElasticsearchSerializer serializer = null
)
{
if (connectionConfiguration == null)
throw new ArgumentNullException("connectionConfiguration");
IConnectionConfigurationValues values = connectionConfiguration;
return Elasticsearch(loggerConfiguration, new ElasticsearchSinkOptions(values.ConnectionPool)
{
Serializer = serializer,
FormatProvider = formatProvider,
IndexFormat = indexFormat,
ModifyConnectionSetttings = s => connectionConfiguration,
BatchPostingLimit = batchPostingLimit,
Period = period,
MinimumLogEventLevel = restrictedToMinimumLevel
});
}

/// <summary>
/// Adds a sink that writes log events as documents to an ElasticSearch index.
Expand All @@ -180,14 +39,17 @@ public static class LoggerConfigurationElasticSearchExtensions
/// <param name="loggerSinkConfiguration"></param>
/// <param name="options">Provides options specific to the Elasticsearch sink</param>
/// <returns></returns>
public static LoggerConfiguration Elasticsearch(this LoggerSinkConfiguration loggerSinkConfiguration, ElasticsearchSinkOptions options = null)
public static LoggerConfiguration Elasticsearch(
this LoggerSinkConfiguration loggerSinkConfiguration,
ElasticsearchSinkOptions options = null)
{
//TODO make sure we do not kill appdata injection
//TODO handle bulk errors and write to self log, what does logstash do in this case?
//TODO NEST trace logging ID's to corrolate requests to eachother
//Deal with positional formatting in fields property (default to scalar string in mapping)
options = options ?? new ElasticsearchSinkOptions(new [] { new Uri("http://localhost:9200") });

var sink = string.IsNullOrWhiteSpace(options.BufferBaseFilename)
? (ILogEventSink) new ElasticsearchSink(options)
: new DurableElasticSearchSink(options);

var sink = new ElasticsearchSink(options);
sink.RegisterTemplateIfNeeded();
return loggerSinkConfiguration.Sink(sink, options.MinimumLogEventLevel ?? LevelAlias.Minimum);
}
}
Expand Down

0 comments on commit 010af25

Please sign in to comment.