Skip to content

Commit

Permalink
Merge pull request #1 from Applicita/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
johnkattenhorn committed Nov 14, 2015
2 parents 584edeb + 47febe6 commit e57f99a
Show file tree
Hide file tree
Showing 17 changed files with 1,331 additions and 6 deletions.
183 changes: 183 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# User-specific files
*.suo
*.user
*.sln.docstates

# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
build/
bld/
[Bb]in/
[Oo]bj/

# Roslyn cache directories
*.ide/

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*

#NUNIT
*.VisualState.xml
TestResult.xml

# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c

*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc

# Chutzpah Test files
_Chutzpah*

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile

# Visual Studio profiler
*.psess
*.vsp
*.vspx

# TFS 2012 Local Workspace
$tf/

# Guidance Automation Toolkit
*.gpState

# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user

# JustCode is a .NET coding addin-in
.JustCode

# TeamCity is a build add-in
_TeamCity*

# DotCover is a Code Coverage Tool
*.dotCover

# NCrunch
_NCrunch_*
.*crunch*.local.xml

# MightyMoose
*.mm.*
AutoTest.Net/

# Web workbench (sass)
.sass-cache/

# Installshield output folder
[Ee]xpress/

# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html

# Click-Once directory
publish/

# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj

# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# If using the old MSBuild-Integrated Package Restore, uncomment this:
#!**/packages/repositories.config

# Windows Azure Build Output
csx/
*.build.csdef

# Windows Store app package directory
AppPackages/

# Others
sql/
*.Cache
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.pfx
*.publishsettings
node_modules/

# RIA/Silverlight projects
Generated_Code/

# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm

# SQL Server files
*.mdf
*.ldf

# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings

# Microsoft Fakes
FakesAssemblies/
32 changes: 26 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@

A Serilog sink that writes events to the [NewRelic](https://newrelic.com) apm application.

[![Package Logo](http://serilog.net/images/serilog-sink-seq-nuget.png)](http://nuget.org/packages/serilog.sinks.seq)

## Getting started

To get started install the _Serilog.Sinks.Seq_ package from Visual Studio's _NuGet_ console:
Install NewRelic NuGetPackage

Configure NewRelic Settings:

```powershell
PM> Install-Package Serilog.Sinks.Seq
```xml
<appSettings>
<add key="NewRelic.LicenseKey" value="<API Key here>"/>
<add key="NewRelic.AgentEnabled" value="true"/>
<add key="NewRelic.AppName" value="Serilog.Sinks.NewRelic.Sample"/>
</appSettings>
```

Point the logger to NewRelic:

```csharp
Log.Logger = new LoggerConfiguration()
.WriteTo.NewRelic()
.WriteTo.NewRelic(applicationName: "Serilog.Sinks.NewRelic.Sample")
.CreateLogger();
```

Expand All @@ -24,3 +28,19 @@ And use the Serilog logging methods to associate named properties with log event
```csharp
Log.Error("Failed to log on user {ContactId}", contactId);
```

The sink also supports sending Serilog.Metrics to NewRelic although this requires a custom transaction in NewRelic See [here](https://docs.newrelic.com/docs/agents/net-agent/instrumentation/net-custom-instrumentation) and may turn out to be largely redundant!

```csharp
// Adding a custom transaction
using (logger.BeginTimedOperation("Time a thread sleep for 2 seconds."))
{
Thread.Sleep(1000);
using (logger.BeginTimedOperation("And inside we try a Task.Delay for 2 seconds."))
{
Task.Delay(2000).Wait();
}
Thread.Sleep(1000);
}
```
19 changes: 19 additions & 0 deletions Serilog.Sinks.NewRelic.Sample/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/>
</startup>
<appSettings>
<add key="NewRelic.LicenseKey" value="1a02e47eb0e63e99cca4dce26d14b28a55fc3040"/>
<add key="NewRelic.AgentEnabled" value="true"/>
<add key="NewRelic.AppName" value="Serilog.Sinks.NewRelic.Sample"/>
</appSettings>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Serilog" publicKeyToken="24c2f752a8e58a10" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-1.5.0.0" newVersion="1.5.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
94 changes: 94 additions & 0 deletions Serilog.Sinks.NewRelic.Sample/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Serilog.Enrichers;
using Serilog.Events;

namespace Serilog.Sinks.NewRelic.Sample
{
class Program
{
static void Main(string[] args)
{
var logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.ColoredConsole(
outputTemplate: "{Timestamp:HH:mm:ss} ({ThreadId}) [{Level}] {Message}{NewLine}{Exception}")
.WriteTo.Trace()
.WriteTo.NewRelic(applicationName: "Serilog.Sinks.NewRelic.Sample")
.Enrich.With(new ThreadIdEnricher(), new MachineNameEnricher())
.CreateLogger();

logger.Information("This is a simple information message {Property1}",100);

// Adding a custom transaction

using (logger.BeginTimedOperation("Time a thread sleep for 2 seconds."))
{
Thread.Sleep(1000);
using (logger.BeginTimedOperation("And inside we try a Task.Delay for 2 seconds."))
{
Task.Delay(2000).Wait();
}
Thread.Sleep(1000);
}

using (logger.BeginTimedOperation("Using a passed in identifier", "test-loop"))
{
// ReSharper disable once NotAccessedVariable
var a = "";
for (var i = 0; i < 1000; i++)
{
a += "b";
}
}

// Exceed a limit
using (logger.BeginTimedOperation("This should execute within 1 second.", null, LogEventLevel.Debug, TimeSpan.FromSeconds(1)))
{
Thread.Sleep(1100);
}

// Gauge

var queue = new Queue<int>();
var gauge = logger.GaugeOperation("queue", "item(s)", () => queue.Count());

gauge.Write();

queue.Enqueue(20);

gauge.Write();

queue.Dequeue();

gauge.Write();

// Counter
var counter = logger.CountOperation("counter", "operation(s)", true, LogEventLevel.Debug, resolution: 2);
counter.Increment();
counter.Increment();
counter.Increment();
counter.Decrement();

// Throw Exception
try
{
throw new ApplicationException("This is an exception raised to test the New Relic API");
}
catch (Exception ex)
{
logger.Error(ex, "Error whilst testing the Serilog.Sinks.NewRelic.Sample");
}



System.Console.WriteLine("Press a key to exit.");
System.Console.ReadKey(true);

}
}
}
36 changes: 36 additions & 0 deletions Serilog.Sinks.NewRelic.Sample/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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: AssemblyTitle("Serilog.Sinks.NewRelic.Sample")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Serilog.Sinks.NewRelic.Sample")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// 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("569471cf-2fb0-434b-9f8e-58784efb6f78")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Loading

0 comments on commit e57f99a

Please sign in to comment.