Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using System.Threading;
using Newtonsoft.Json;

namespace Microsoft.Extensions.Logging.EventSourceLogger
namespace Microsoft.Extensions.Logging.EventSource
{
/// <summary>
/// A logger that writes messages to EventSource instance.
Expand All @@ -19,9 +19,9 @@ namespace Microsoft.Extensions.Logging.EventSourceLogger
/// </remarks>
internal class EventSourceLogger : ILogger
{
private static int _activityIds;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_activityId? Also, should this be a non-static. cc @davidfowl for an opinion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's used to get unique id's for scopes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, this is not the logger provider. Ok. Seems crummy though to rely on statics to do this.

private readonly LoggingEventSource _eventSource;
private readonly int _factoryID;
private static int s_activityIds;

public EventSourceLogger(string categoryName, int factoryID, LoggingEventSource eventSource, EventSourceLogger next)
{
Expand Down Expand Up @@ -131,7 +131,7 @@ public IDisposable BeginScope<TState>(TState state)
return NoopDisposable.Instance;
}

var id = Interlocked.Increment(ref s_activityIds);
var id = Interlocked.Increment(ref _activityIds);

// If JsonMessage is on, use JSON format
if (_eventSource.IsEnabled(EventLevel.Critical, LoggingEventSource.Keywords.JsonMessage))
Expand Down Expand Up @@ -188,7 +188,7 @@ public void Dispose()

private class NoopDisposable : IDisposable
{
public static NoopDisposable Instance = new NoopDisposable();
public static readonly NoopDisposable Instance = new NoopDisposable();

public void Dispose()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using Microsoft.Extensions.Logging.EventSourceLogger;
using Microsoft.Extensions.Logging.EventSource;

namespace Microsoft.Extensions.Logging
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System;
using System.Diagnostics.Tracing;

namespace Microsoft.Extensions.Logging.EventSourceLogger
namespace Microsoft.Extensions.Logging.EventSource
{
/// <summary>
/// The provider for the <see cref="EventSourceLogger"/>.
Expand Down Expand Up @@ -32,9 +32,7 @@ public EventSourceLoggerProvider(LoggingEventSource eventSource, EventSourceLogg

public EventSourceLoggerProvider Next { get; }

/// <summary>
/// <inheritdoc />
/// </summary>
public ILogger CreateLogger(string categoryName)
{
// need to check if the filter spec and internal event source level has changed
Expand All @@ -51,7 +49,7 @@ public void Dispose()
}

// Sets the filtering for a particular logger provider
public void SetFilterSpec(string filterSpec)
internal void SetFilterSpec(string filterSpec)
{
_filterSpec = filterSpec;
_defaultLevel = GetDefaultLevel();
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.Extensions.Logging.EventSource/ExceptionInfo.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

namespace Microsoft.Extensions.Logging.EventSourceLogger
namespace Microsoft.Extensions.Logging.EventSource
{
/// <summary>
/// Represents information about exceptions that is captured by EventSourceLogger
Expand All @@ -14,6 +14,6 @@ internal class ExceptionInfo
public string TypeName { get; set; }
public string Message { get; set; }
public int HResult { get; set; }
public string VerboseMessage { get; set; } // This is the ToString() of the Exception
public string VerboseMessage { get; set; } // This is the ToString() of the Exception
}
}
23 changes: 11 additions & 12 deletions src/Microsoft.Extensions.Logging.EventSource/LoggingEventSource.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Collections.Generic;
using System.Diagnostics.Tracing;

namespace Microsoft.Extensions.Logging.EventSourceLogger
namespace Microsoft.Extensions.Logging.EventSource
{
/// <summary>
/// The LoggingEventSource is the bridge form all ILogger based logging to EventSource/EventListener logging.
Expand Down Expand Up @@ -70,7 +69,7 @@ namespace Microsoft.Extensions.Logging.EventSourceLogger
/// }
/// </summary>
[EventSource(Name = "Microsoft-Extensions-Logging")]
public class LoggingEventSource : EventSource
internal class LoggingEventSource : System.Diagnostics.Tracing.EventSource
{
/// <summary>
/// This is public from an EventSource consumer point of view, but since these defintions
Expand Down Expand Up @@ -103,14 +102,14 @@ public class Keywords

internal static readonly LogLevel LoggingDisabled = LogLevel.None + 1;

private readonly object _providerLock = new object();
private string _filterSpec;
private EventSourceLoggerProvider _loggingProviders;
private object _lockObj = new object();
private bool _checkLevel;

internal EventSourceLoggerProvider CreateLoggerProvider()
{
lock (_lockObj)
lock (_providerLock)
{
var newLoggerProvider = new EventSourceLoggerProvider(this, _loggingProviders);
_loggingProviders = newLoggerProvider;
Expand Down Expand Up @@ -197,24 +196,24 @@ internal void ActivityJsonStop(int ID, int FactoryID, string LoggerName)
WriteEvent(7, ID, FactoryID, LoggerName);
}

/// <summary>
/// <inheritdoc />
/// </summary>
protected override void OnEventCommand(EventCommandEventArgs command)
{
lock (_lockObj)
lock (_providerLock)
{
if ((command.Command == EventCommand.Update || command.Command == EventCommand.Enable))
if (command.Command == EventCommand.Update || command.Command == EventCommand.Enable)
{
string filterSpec;
if (!command.Arguments.TryGetValue("FilterSpecs", out filterSpec))
filterSpec = ""; // This means turn on everything.
{
filterSpec = string.Empty; // This means turn on everything.
}

SetFilterSpec(filterSpec);
}
else if (command.Command == EventCommand.Update || command.Command == EventCommand.Disable)
{
SetFilterSpec(null); // This means disable everything.
SetFilterSpec(null); // This means disable everything.
}
}
}
Expand All @@ -238,7 +237,7 @@ private void SetFilterSpec(string filterSpec)
[NonEvent]
internal void ApplyFilterSpec()
{
lock (_lockObj)
lock (_providerLock)
{
if (_checkLevel)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Microsoft.Extensions.Logging.EventSource.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]

[assembly: AssemblyMetadata("Serviceable", "True")]
[assembly: NeutralResourcesLanguage("en-us")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Diagnostics.Tracing;
using System.IO;
using System.Linq;
using Microsoft.Extensions.Logging.EventSourceLogger;
using Microsoft.Extensions.Logging.EventSource;
using Newtonsoft.Json;
using Xunit;

Expand Down Expand Up @@ -421,7 +421,7 @@ public class ListenerSettings
public string FilterSpec;
}

private EventSource _loggingEventSource;
private System.Diagnostics.Tracing.EventSource _loggingEventSource;

public TestEventListener()
{
Expand Down Expand Up @@ -449,7 +449,7 @@ public void EnableEvents(ListenerSettings settings)
EnableEvents(_loggingEventSource, settings.Level, settings.Keywords, args);
}

protected override void OnEventSourceCreated(EventSource eventSource)
protected override void OnEventSourceCreated(System.Diagnostics.Tracing.EventSource eventSource)
{
if (eventSource.Name == "Microsoft-Extensions-Logging")
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"buildOptions": {
"keyFile": "../../tools/Key.snk",
"warningsAsErrors": true
},
"dependencies": {
Expand Down