-
Notifications
You must be signed in to change notification settings - Fork 66
feat: Internal logging now uses Serilog instead of log4net #1661
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c4b0fbc
Initial Serilog Logging Implementation (#1655)
tippmar-nr 29d5c82
feat: Implement simple in-memory Serilog sink. (#1657)
jaffinito 2a857f5
Refactor Unit tests to use Serilog instead of log4net
tippmar-nr d7450fc
Add Serilog.Async sink, wrap Console and File sinks with Async sink. …
tippmar-nr 98dfc0d
log4net to Serilog: Unit tests plus code cleanup for serilog implemen…
tippmar-nr 2cddfb1
log4net to Serilog: Log format cleanup / rework (#1672)
tippmar-nr 2bbbead
Removed an unused enum from configuration.cs
tippmar-nr cf7846c
Re-generated Configuration.cs using xsd2code, looks like only whitesp…
tippmar-nr 75cef9d
Stupid file headers. Grr.
tippmar-nr 6cbcaad
Minor tweak in ProcessIdEnricher
tippmar-nr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
19 changes: 19 additions & 0 deletions
19
src/Agent/NewRelic/Agent/Core/Logging/CustomAuditLogTextFormatter.cs
This file contains hidden or 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 @@ | ||
// Copyright 2020 New Relic, Inc. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
using System.IO; | ||
using Serilog.Events; | ||
using Serilog.Formatting; | ||
|
||
namespace NewRelic.Agent.Core | ||
{ | ||
class CustomAuditLogTextFormatter : ITextFormatter | ||
{ | ||
public void Format(LogEvent logEvent, TextWriter output) | ||
{ | ||
logEvent.Properties.TryGetValue("Message", out var message); | ||
|
||
output.Write($"{logEvent.Timestamp.ToUniversalTime():yyyy-MM-dd HH:mm:ss,fff} NewRelic AUDIT: {message}{output.NewLine}"); | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/Agent/NewRelic/Agent/Core/Logging/CustomTextFormatter.cs
This file contains hidden or 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,24 @@ | ||
// Copyright 2020 New Relic, Inc. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
using System.IO; | ||
using Serilog.Events; | ||
using Serilog.Formatting; | ||
|
||
namespace NewRelic.Agent.Core | ||
{ | ||
class CustomTextFormatter : ITextFormatter | ||
{ | ||
public void Format(LogEvent logEvent, TextWriter output) | ||
{ | ||
// try to get process and thread id | ||
logEvent.Properties.TryGetValue("pid", out var pid); | ||
logEvent.Properties.TryGetValue("tid", out var tid); | ||
|
||
// format matches the log4net format, but adds the Exception property (if present in the message as a separate property) to the end, after the newline | ||
// if that's not desired, take the Exception property out and refactor calls to `Serilog.Log.Logger.LogXxxx(exception, message)` so the exception is | ||
// formatted into the message | ||
output.Write($"{logEvent.Timestamp.ToUniversalTime():yyyy-MM-dd HH:mm:ss,fff} NewRelic {logEvent.Level.TranslateLogLevel(),6}: [pid: {pid?.ToString()}, tid: {tid?.ToString()}] {logEvent.MessageTemplate}{output.NewLine}{logEvent.Exception}"); | ||
} | ||
} | ||
} |
This file contains hidden or 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,45 @@ | ||
// Copyright 2020 New Relic, Inc. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
using System; | ||
using Serilog.Core; | ||
using Serilog.Events; | ||
using System.Collections.Concurrent; | ||
using System.Collections.Generic; | ||
|
||
namespace NewRelic.Agent.Core.Logging | ||
{ | ||
public class InMemorySink : ILogEventSink, IDisposable | ||
{ | ||
private readonly ConcurrentQueue<LogEvent> _logEvents; | ||
|
||
public InMemorySink() | ||
{ | ||
_logEvents = new ConcurrentQueue<LogEvent>(); | ||
} | ||
|
||
public void Emit(LogEvent logEvent) | ||
{ | ||
_logEvents.Enqueue(logEvent); | ||
} | ||
|
||
public IEnumerable<LogEvent> LogEvents | ||
{ | ||
get | ||
{ | ||
return _logEvents; | ||
} | ||
} | ||
|
||
public void Clear() | ||
{ | ||
while (_logEvents.TryDequeue(out _)) | ||
{ } | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
Clear(); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.