Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

Commit

Permalink
Merge pull request #7 from Authenticom/develop
Browse files Browse the repository at this point in the history
Added appSettings support for key and endpoint config
  • Loading branch information
sirkirby authored Sep 19, 2017
2 parents eb1218e + 3f3cea7 commit 113492b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ All log events are sent to a custom event grid topic as an HTTP Post. For more i
## Usage

```csharp
// Full
Log.Logger = new LoggerConfiguration()
.WriteTo.EventGrid("TopicKeyorSASTokenString",
"https://my-topic-name.westus2-1.eventgrid.azure.net/api/events",
Expand All @@ -21,6 +22,9 @@ Log.Logger = new LoggerConfiguration()
"EventPropertyName",
restrictedToMinimumLevel: LogEventLevel.Information)
.CreateLogger()

// Min
Log.Logger = new LoggerConfiguration().WriteTo.EventGrid().CreateLogger()
```

### Required
Expand All @@ -33,6 +37,15 @@ The primary or secondary topic key, recommended for the most trusted events, or,

The full topic uri, containing custom topic name and region. You can see this in the azure portal or retrieve it via the azue cli.

Alternatively, you can pass the **key** and **topicEndPoint** through your `<appSettings>`:

```xml
<appSettings>
<add key="EventGridTopicKey" value="TopicKeyorSASTokenString" />
<add key="EventGridTopicUri" value="https://my-topic-name.westus2-1.eventgrid.azure.net/api/events" />
</appSettings>
```

### Optional

**customEventSubject** (string)
Expand All @@ -59,6 +72,10 @@ Name of the property added to the Serilog log event that will contain the Type o
Log.ForContext("EventPropertyName", "myCustomType").Information("{@OtherData}", otherData)
```

**restrictedToMinimumLevel** (enum)

Specify the Serilog logging level. Default is `LogEventLevel.Information`

### Custom Attributes

As an alternative to specifying the subject and type through log configuration or properties, you can decorate your code at design time with the `[EventGridSubject]` and `[EventGridType]` Attributes. Any method or class is supported, using one or both on each. The Serilog log event called within the context of a method or class decorated with either attribute, will use those values when submitting the event. The first ones closest to the log event call in the stack, win.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Configuration;
using Serilog.Configuration;
using Serilog.Events;
using Serilog.Sinks.EventGrid;
Expand All @@ -9,8 +10,8 @@ public static class LoggerConfigurationEventGridExtensions
{
public static LoggerConfiguration EventGrid(
this LoggerSinkConfiguration loggerConfiguration,
string key,
string topicEndpoint,
string key = null,
string topicEndpoint = null,
string customEventSubject = null,
string customEventType = null,
string customSubjectPropertyName = "EventSubject",
Expand All @@ -21,6 +22,10 @@ public static LoggerConfiguration EventGrid(
{
if (loggerConfiguration == null) throw new ArgumentNullException("loggerConfiguration");

// allow null and pull from app configuration
key = key ?? ConfigurationManager.AppSettings["EventGridTopicKey"];
topicEndpoint = topicEndpoint ?? ConfigurationManager.AppSettings["EventGridTopicUri"];

if (string.IsNullOrWhiteSpace(key))
throw new ArgumentNullException("key");

Expand Down
2 changes: 2 additions & 0 deletions src/Serilog.Sinks.EventGrid/Serilog.Sinks.EventGrid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<RepositoryUrl>https://github.com/Authenticom/serilog-sinks-eventgrid</RepositoryUrl>
<PackageTags>serilog events eventgrid</PackageTags>
<Copyright>Copyright © Chris Kirby 2017</Copyright>
<Version>1.0.1</Version>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net461'">
Expand All @@ -25,6 +26,7 @@
<ItemGroup>
<PackageReference Include="newtonsoft.json" Version="10.0.3" />
<PackageReference Include="serilog" Version="2.5.0" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.4.0" />
</ItemGroup>

</Project>

0 comments on commit 113492b

Please sign in to comment.