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 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from serilog/dev
4.0.0 Release
- Loading branch information
Showing
17 changed files
with
1,146 additions
and
73 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
using System; | ||
using Loggly; | ||
using Loggly.Config; | ||
using Serilog; | ||
using Serilog.Core; | ||
using Serilog.Core.Enrichers; | ||
using Serilog.Enrichers; | ||
using Serilog.Sinks.RollingFileAlternate; | ||
|
||
namespace SampleDurableLogger | ||
{ | ||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
SetupLogglyConfiguration(); | ||
using (var logger = CreateLogger(@"c:\test\")) | ||
{ | ||
logger.Information("Test message - app started"); | ||
logger.Warning("Test message with {@Data}", new {P1 = "sample", P2 = DateTime.Now}); | ||
logger.Warning("Test2 message with {@Data}", new {P1 = "sample2", P2 = 10}); | ||
|
||
Console.WriteLine( | ||
"Disconnect to test offline. Two messages will be sent. Press enter to send and wait a minute or so before reconnecting or use breakpoints to see that send fails."); | ||
Console.ReadLine(); | ||
|
||
logger.Information("Second test message"); | ||
logger.Warning("Second test message with {@Data}", new {P1 = "sample2", P2 = DateTime.Now}); | ||
|
||
|
||
Console.WriteLine( | ||
"Offline messages written. Once you have confirmed that messages have been written locally, reconnect to see messages go out. Press Enter for more messages to be written."); | ||
Console.ReadLine(); | ||
|
||
logger.Information("Third test message"); | ||
logger.Warning("Third test message with {@Data}", new {P1 = "sample3", P2 = DateTime.Now}); | ||
|
||
Console.WriteLine( | ||
"Back online messages written. Check loggly and files for data. Wait a minute or so before reconnecting. Press Enter to terminate"); | ||
Console.ReadLine(); | ||
} | ||
} | ||
|
||
static Logger CreateLogger(string logFilePath) | ||
{ | ||
return new LoggerConfiguration() | ||
.MinimumLevel.Debug() | ||
//Add enrichers | ||
.Enrich.FromLogContext() | ||
.Enrich.WithProcessId() | ||
.Enrich.WithThreadId() | ||
.Enrich.With(new EnvironmentUserNameEnricher()) | ||
.Enrich.With(new MachineNameEnricher()) | ||
.Enrich.With(new PropertyEnricher("Environment", "development")) | ||
//Add sinks | ||
.WriteTo.Async(s => s.Loggly( | ||
bufferBaseFilename: logFilePath + "buffer") | ||
.MinimumLevel.Information() | ||
) | ||
.WriteTo.Async(s => s.RollingFileAlternate( | ||
logFilePath, | ||
outputTemplate: | ||
"[{ProcessId}] {Timestamp:yyyy-MM-dd HH:mm:ss.fff K} [{ThreadId}] [{Level}] [{SourceContext}] [{Category}] {Message}{NewLine}{Exception}", | ||
fileSizeLimitBytes: 10 * 1024 * 1024, | ||
retainedFileCountLimit: 100) | ||
.MinimumLevel.Debug() | ||
) | ||
.CreateLogger(); | ||
} | ||
|
||
|
||
static void SetupLogglyConfiguration() | ||
{ | ||
///CHANGE THESE TWO TO YOUR LOGGLY ACCOUNT: DO NOT COMMIT TO Source control!!! | ||
const string appName = "AppNameHere"; | ||
const string customerToken = "yourkeyhere"; | ||
|
||
//Configure Loggly | ||
var config = LogglyConfig.Instance; | ||
config.CustomerToken = customerToken; | ||
config.ApplicationName = appName; | ||
config.Transport = new TransportConfiguration() | ||
{ | ||
EndpointHostname = "logs-01.loggly.com", | ||
EndpointPort = 443, | ||
LogTransport = LogTransport.Https | ||
}; | ||
config.ThrowExceptions = true; | ||
|
||
//Define Tags sent to Loggly | ||
config.TagConfig.Tags.AddRange(new ITag[]{ | ||
new ApplicationNameTag {Formatter = "application-{0}"}, | ||
new HostnameTag { Formatter = "host-{0}" } | ||
}); | ||
} | ||
} | ||
} |
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,19 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("Microsoft")] | ||
[assembly: AssemblyProduct("sampleDurableLogger")] | ||
[assembly: AssemblyTrademark("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("a47ed1ce-fe7c-444e-9391-10d6b60519c2")] |
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,31 @@ | ||
{ | ||
"version": "1.0.0-*", | ||
"buildOptions": { | ||
"emitEntryPoint": true | ||
}, | ||
|
||
"dependencies": { | ||
"Microsoft.NETCore.App": { | ||
"type": "platform", | ||
"version": "1.0.0" | ||
}, | ||
"loggly-csharp": "4.6.0.5", | ||
"Newtonsoft.Json": "9.0.1", | ||
"Serilog": "2.3.0", | ||
"Serilog.Sinks.PeriodicBatching": "2.0.0", | ||
"Serilog.Sinks.File": "3.1.1", | ||
"Serilog.Sinks.RollingFile": "3.2.0", | ||
"Serilog.Sinks.RollingFileAlternate": "2.0.6", | ||
"Serilog.Sinks.Async": "1.0.1", | ||
"Serilog.Enrichers.Environment": "2.1.1", | ||
"Serilog.Enrichers.Process": "2.0.0", | ||
"Serilog.Enrichers.Thread": "3.0.0", | ||
"Serilog.Sinks.Loggly": "3.0.3-*" | ||
}, | ||
|
||
"frameworks": { | ||
"netcoreapp1.0": { | ||
"imports": "dnxcore50" | ||
} | ||
} | ||
} |
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,21 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion> | ||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> | ||
</PropertyGroup> | ||
|
||
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" /> | ||
<PropertyGroup Label="Globals"> | ||
<ProjectGuid>a47ed1ce-fe7c-444e-9391-10d6b60519c2</ProjectGuid> | ||
<RootNamespace>sampleDurableLogger</RootNamespace> | ||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath> | ||
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath> | ||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
</PropertyGroup> | ||
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" /> | ||
</Project> |
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Serilog.Sinks.Seq Copyright 2016 Serilog Contributors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using Serilog.Core; | ||
using Serilog.Events; | ||
|
||
namespace Serilog.Sinks.Loggly | ||
{ | ||
/// <summary> | ||
/// Instances of this type are single-threaded, generally only updated on a background | ||
/// timer thread. An exception is <see cref="IsIncluded(LogEvent)"/>, which may be called | ||
/// concurrently but performs no synchronization. | ||
/// </summary> | ||
class ControlledLevelSwitch | ||
{ | ||
// If non-null, then background level checks will be performed; set either through the constructor | ||
// or in response to a level specification from the server. Never set to null after being made non-null. | ||
LoggingLevelSwitch _controlledSwitch; | ||
LogEventLevel? _originalLevel; | ||
|
||
public ControlledLevelSwitch(LoggingLevelSwitch controlledSwitch = null) | ||
{ | ||
_controlledSwitch = controlledSwitch; | ||
} | ||
|
||
public bool IsActive => _controlledSwitch != null; | ||
|
||
public bool IsIncluded(LogEvent evt) | ||
{ | ||
// Concurrent, but not synchronized. | ||
var controlledSwitch = _controlledSwitch; | ||
return controlledSwitch == null || | ||
(int)controlledSwitch.MinimumLevel <= (int)evt.Level; | ||
} | ||
|
||
public void Update(LogEventLevel? minimumAcceptedLevel) | ||
{ | ||
if (minimumAcceptedLevel == null) | ||
{ | ||
if (_controlledSwitch != null && _originalLevel.HasValue) | ||
_controlledSwitch.MinimumLevel = _originalLevel.Value; | ||
|
||
return; | ||
} | ||
|
||
if (_controlledSwitch == null) | ||
{ | ||
// The server is controlling the logging level, but not the overall logger. Hence, if the server | ||
// stops controlling the level, the switch should become transparent. | ||
_originalLevel = LevelAlias.Minimum; | ||
_controlledSwitch = new LoggingLevelSwitch(minimumAcceptedLevel.Value); | ||
return; | ||
} | ||
|
||
if (!_originalLevel.HasValue) | ||
_originalLevel = _controlledSwitch.MinimumLevel; | ||
|
||
_controlledSwitch.MinimumLevel = minimumAcceptedLevel.Value; | ||
} | ||
} | ||
} |
Oops, something went wrong.