Skip to content
Closed
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 @@ -6,6 +6,18 @@

namespace Microsoft.Extensions.Logging
{
public ref partial struct BufferWriter<T>
{
private object _dummy;
private int _dummyPrimitive;
public BufferWriter(System.Buffers.IBufferWriter<T> bufferWriter) { throw null; }
public System.Span<T> CurrentSpan { get { throw null; } }
public System.Buffers.IBufferWriter<T> Writer { get { throw null; } }
public void Advance(int len) { }
public void EnsureSize(int minSize) { }
public void Flush() { }
public void Grow(int minSize) { }
}
public readonly partial struct EventId : System.IEquatable<Microsoft.Extensions.Logging.EventId>
{
private readonly object _dummy;
Expand All @@ -21,11 +33,29 @@ namespace Microsoft.Extensions.Logging
public static bool operator !=(Microsoft.Extensions.Logging.EventId left, Microsoft.Extensions.Logging.EventId right) { throw null; }
public override string ToString() { throw null; }
}
public delegate void FormatPropertyAction<PropType>(PropType propertyValue, ref Microsoft.Extensions.Logging.BufferWriter<byte> bufferWriter);
public delegate void FormatPropertyListAction<TState>(in TState state, ref Microsoft.Extensions.Logging.BufferWriter<byte> bufferWriter);
public delegate void FormatSpanPropertyAction(System.ReadOnlySpan<char> propertyValue, ref Microsoft.Extensions.Logging.BufferWriter<byte> bufferWriter);
public partial interface IExternalScopeProvider
{
void ForEachScope<TState>(System.Action<object?, TState> callback, TState state);
System.IDisposable Push(object? state);
}
public partial interface ILogEntryPipelineFactory
{
Microsoft.Extensions.Logging.LogEntryPipeline<TState>? GetLoggingPipeline<TState>(Microsoft.Extensions.Logging.ILogMetadata<TState>? metadata, object? userState);
Microsoft.Extensions.Logging.ScopePipeline<TState>? GetScopePipeline<TState>(Microsoft.Extensions.Logging.ILogMetadata<TState>? metadata, object? userState) where TState : notnull;
}
public partial interface ILogEntryProcessor
{
Microsoft.Extensions.Logging.LogEntryHandler<TState> GetLogEntryHandler<TState>(Microsoft.Extensions.Logging.ILogMetadata<TState>? metadata, out bool enabled, out bool dynamicEnabledCheckRequired);
Microsoft.Extensions.Logging.ScopeHandler<TState> GetScopeHandler<TState>(Microsoft.Extensions.Logging.ILogMetadata<TState>? metadata, out bool enabled) where TState : notnull;
bool IsEnabled(Microsoft.Extensions.Logging.LogLevel logLevel);
}
public partial interface ILogEntryProcessorFactory
{
Microsoft.Extensions.Logging.ProcessorContext GetProcessor();
}
public partial interface ILogger
{
System.IDisposable? BeginScope<TState>(TState state) where TState : notnull;
Expand All @@ -44,15 +74,49 @@ public partial interface ILoggerProvider : System.IDisposable
public partial interface ILogger<out TCategoryName> : Microsoft.Extensions.Logging.ILogger
{
}
public partial interface ILogMetadata<TState>
{
Microsoft.Extensions.Logging.EventId EventId { get; }
Microsoft.Extensions.Logging.LogLevel LogLevel { get; }
string OriginalFormat { get; }
int PropertyCount { get; }
void AppendFormattedMessage(in TState state, System.Buffers.IBufferWriter<char> buffer);
System.Action<TState, System.Buffers.IBufferWriter<char>> GetMessageFormatter(Microsoft.Extensions.Logging.PropertyCustomFormatter[] customFormatters);
Microsoft.Extensions.Logging.LogPropertyInfo GetPropertyInfo(int index);
Microsoft.Extensions.Logging.FormatPropertyListAction<TState> GetPropertyListFormatter(Microsoft.Extensions.Logging.IPropertyFormatterFactory propertyFormatterFactory);
System.Func<TState, System.Exception?, string> GetStringMessageFormatter();
}
public partial interface IProcessorFactory
{
Microsoft.Extensions.Logging.ILogEntryProcessor GetProcessor(Microsoft.Extensions.Logging.ILogEntryProcessor nextProcessor);
}
public partial interface IPropertyFormatterFactory
{
Microsoft.Extensions.Logging.FormatPropertyAction<PropType> GetPropertyFormatter<PropType>(int propertyIndex, Microsoft.Extensions.Logging.LogPropertyInfo metadata);
Microsoft.Extensions.Logging.FormatSpanPropertyAction GetSpanPropertyFormatter(int propertyIndex, Microsoft.Extensions.Logging.LogPropertyInfo metadata);
}
public partial interface ISupportExternalScope
{
void SetScopeProvider(Microsoft.Extensions.Logging.IExternalScopeProvider scopeProvider);
}
public partial class LogDefineOptions
{
public LogDefineOptions() { }
public object[]?[]? ParameterMetadata { get { throw null; } set { } }
public bool SkipEnabledCheck { get { throw null; } set { } }
}
public abstract partial class LogEntryHandler<TState>
{
protected LogEntryHandler() { }
public abstract void HandleLogEntry(ref Microsoft.Extensions.Logging.Abstractions.LogEntry<TState> logEntry);
public abstract bool IsEnabled(Microsoft.Extensions.Logging.LogLevel level);
}
public partial class LogEntryPipeline<TState> : Microsoft.Extensions.Logging.Pipeline
{
public LogEntryPipeline(Microsoft.Extensions.Logging.LogEntryHandler<TState> handler, object? userState, bool isEnabled, bool isDynamicLevelCheckRequired) : base (default(object), default(bool), default(bool)) { }
public void HandleLogEntry(ref Microsoft.Extensions.Logging.Abstractions.LogEntry<TState> logEntry) { }
public bool IsEnabledDynamic(Microsoft.Extensions.Logging.LogLevel level) { throw null; }
}
public static partial class LoggerExtensions
{
public static System.IDisposable? BeginScope(this Microsoft.Extensions.Logging.ILogger logger, string messageFormat, params object?[] args) { throw null; }
Expand Down Expand Up @@ -107,6 +171,7 @@ public static partial class LoggerMessage
public static System.Func<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, T4, System.IDisposable?> DefineScope<T1, T2, T3, T4>(string formatString) { throw null; }
public static System.Func<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, T4, T5, System.IDisposable?> DefineScope<T1, T2, T3, T4, T5>(string formatString) { throw null; }
public static System.Func<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, T4, T5, T6, System.IDisposable?> DefineScope<T1, T2, T3, T4, T5, T6>(string formatString) { throw null; }
public static Microsoft.Extensions.Logging.LoggerMessage.Log<TState> Define<TState>(Microsoft.Extensions.Logging.ILogMetadata<TState> metadata, Microsoft.Extensions.Logging.LogDefineOptions? options = null) { throw null; }
public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, System.Exception?> Define<T1>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString) { throw null; }
public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, System.Exception?> Define<T1>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString, Microsoft.Extensions.Logging.LogDefineOptions? options) { throw null; }
public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, System.Exception?> Define<T1, T2>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString) { throw null; }
Expand All @@ -119,6 +184,7 @@ public static partial class LoggerMessage
public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, T4, T5, System.Exception?> Define<T1, T2, T3, T4, T5>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString, Microsoft.Extensions.Logging.LogDefineOptions? options) { throw null; }
public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, T4, T5, T6, System.Exception?> Define<T1, T2, T3, T4, T5, T6>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString) { throw null; }
public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, T4, T5, T6, System.Exception?> Define<T1, T2, T3, T4, T5, T6>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString, Microsoft.Extensions.Logging.LogDefineOptions? options) { throw null; }
public delegate void Log<TState>(Microsoft.Extensions.Logging.ILogger logger, ref TState state, System.Exception? exception);
}
[System.AttributeUsageAttribute(System.AttributeTargets.Method)]
public sealed partial class LoggerMessageAttribute : System.Attribute
Expand All @@ -131,10 +197,12 @@ public LoggerMessageAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel
public string Message { get { throw null; } set { } }
public bool SkipEnabledCheck { get { throw null; } set { } }
}
public partial class Logger<T> : Microsoft.Extensions.Logging.ILogger, Microsoft.Extensions.Logging.ILogger<T>
public partial class Logger<T> : Microsoft.Extensions.Logging.ILogEntryPipelineFactory, Microsoft.Extensions.Logging.ILogger, Microsoft.Extensions.Logging.ILogger<T>
{
public Logger(Microsoft.Extensions.Logging.ILoggerFactory factory) { }
System.IDisposable? Microsoft.Extensions.Logging.ILogger.BeginScope<TState>(TState state) { throw null; }
Microsoft.Extensions.Logging.LogEntryPipeline<TState> Microsoft.Extensions.Logging.ILogEntryPipelineFactory.GetLoggingPipeline<TState>(Microsoft.Extensions.Logging.ILogMetadata<TState>? metadata, object? userState) { throw null; }
Microsoft.Extensions.Logging.ScopePipeline<TState> Microsoft.Extensions.Logging.ILogEntryPipelineFactory.GetScopePipeline<TState>(Microsoft.Extensions.Logging.ILogMetadata<TState>? metadata, object? userState) { throw null; }
System.IDisposable Microsoft.Extensions.Logging.ILogger.BeginScope<TState>(TState state) { throw null; }
bool Microsoft.Extensions.Logging.ILogger.IsEnabled(Microsoft.Extensions.Logging.LogLevel logLevel) { throw null; }
void Microsoft.Extensions.Logging.ILogger.Log<TState>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, TState state, System.Exception? exception, System.Func<TState, System.Exception?, string> formatter) { }
}
Expand All @@ -148,6 +216,54 @@ public enum LogLevel
Critical = 5,
None = 6,
}
public partial struct LogPropertyInfo
{
private object _dummy;
private int _dummyPrimitive;
public LogPropertyInfo(string name, object[]? metadata) { throw null; }
public readonly object[]? Metadata { get { throw null; } }
public readonly string Name { get { throw null; } }
}
public partial class Pipeline
{
public Pipeline(object? userState, bool isEnabled, bool isDynamicLevelCheckRequired) { }
public bool IsDynamicLevelCheckRequired { get { throw null; } }
public bool IsEnabled { get { throw null; } }
public bool IsUpToDate { get { throw null; } set { } }
public object? UserState { get { throw null; } }
}
public readonly partial struct ProcessorContext
{
private readonly object _dummy;
private readonly int _dummyPrimitive;
public ProcessorContext(Microsoft.Extensions.Logging.ILogEntryProcessor processor, System.Threading.CancellationToken cancellationToken) { throw null; }
public System.Threading.CancellationToken CancellationToken { get { throw null; } }
public Microsoft.Extensions.Logging.ILogEntryProcessor Processor { get { throw null; } }
}
public partial class ProcessorFactory<T> : Microsoft.Extensions.Logging.IProcessorFactory where T : Microsoft.Extensions.Logging.ILogEntryProcessor
{
public ProcessorFactory(System.Func<Microsoft.Extensions.Logging.ILogEntryProcessor, T> getProcessor) { }
public Microsoft.Extensions.Logging.ILogEntryProcessor GetProcessor(Microsoft.Extensions.Logging.ILogEntryProcessor nextProcessor) { throw null; }
}
public abstract partial class PropertyCustomFormatter
{
protected PropertyCustomFormatter() { }
public virtual void AppendFormatted(int index, int value, System.Buffers.IBufferWriter<char> buffer) { }
public virtual void AppendFormatted(int index, System.ReadOnlySpan<char> value, System.Buffers.IBufferWriter<char> buffer) { }
public virtual void AppendFormatted(int index, string value, System.Buffers.IBufferWriter<char> buffer) { }
public abstract void AppendFormatted<T>(int index, T value, System.Buffers.IBufferWriter<char> buffer);
}
public abstract partial class ScopeHandler<TState> where TState : notnull
{
protected ScopeHandler() { }
public abstract System.IDisposable? HandleBeginScope(ref TState state);
public abstract bool IsEnabled(Microsoft.Extensions.Logging.LogLevel level);
}
public partial class ScopePipeline<TState> : Microsoft.Extensions.Logging.Pipeline where TState : notnull
{
public ScopePipeline(Microsoft.Extensions.Logging.ScopeHandler<TState> handler, object? userState, bool isEnabled) : base (default(object), default(bool), default(bool)) { }
public System.IDisposable? HandleScope(ref TState scope) { throw null; }
}
}
namespace Microsoft.Extensions.Logging.Abstractions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@
<ItemGroup>
<Compile Include="Microsoft.Extensions.Logging.Abstractions.cs" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'">
<PackageReference Include="System.Buffers" Version="$(SystemBuffersVersion)" />
<PackageReference Include="System.Memory" Version="$(SystemMemoryVersion)" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Buffers;

namespace Microsoft.Extensions.Logging
{
public ref struct BufferWriter<T>
{
private Span<T> _currentSpan;
private IBufferWriter<T> _writer;
private int _allocated;

public BufferWriter(IBufferWriter<T> bufferWriter)
{
_writer = bufferWriter;
_currentSpan = bufferWriter.GetSpan();
_allocated = _currentSpan.Length;
}

public IBufferWriter<T> Writer => _writer;
public Span<T> CurrentSpan => _currentSpan;

public void Advance(int len)
{
_currentSpan = _currentSpan.Slice(len);
}

public void EnsureSize(int minSize)
{
if (_currentSpan.Length < minSize)
{
Grow(minSize);
}
}

public void Grow(int minSize)
{
if (_allocated != _currentSpan.Length)
{
Flush();
}
_currentSpan = _writer.GetSpan(minSize);
_allocated = _currentSpan.Length;
}

public void Flush()
{
_writer.Advance(_allocated - _currentSpan.Length);
_currentSpan = default;
_allocated = 0;
}
}

internal static class BufferWriterExtensions
{
public static void Write(ref this BufferWriter<char> writer, ReadOnlySpan<char> value)
{
if (!value.TryCopyTo(writer.CurrentSpan))
{
writer.Grow(value.Length);
value.CopyTo(writer.CurrentSpan);
}
writer.Advance(value.Length);
}

public static void Write(ref this BufferWriter<char> writer, ReadOnlySpan<char> value, int alignment)
{
int valueLen = value.Length;
bool leftAlign = false;
if (alignment < 0)
{
leftAlign = true;
alignment = -alignment;
}
int lenNeeded = Math.Max(alignment, valueLen);
int paddingNeeded = lenNeeded - valueLen;
if (writer.CurrentSpan.Length < lenNeeded)
{
writer.Grow(lenNeeded);
}
Span<char> currentSpan = writer.CurrentSpan;
if (leftAlign)
{
currentSpan.Slice(0, paddingNeeded).Fill(' ');
value.CopyTo(currentSpan.Slice(paddingNeeded));
}
else
{
value.CopyTo(currentSpan.Slice(paddingNeeded));
currentSpan.Slice(valueLen, paddingNeeded).Fill(' ');
}
writer.Advance(lenNeeded);
}

/*
public void Append(int value)
{
if (_unusedChars.Length < 20)
{
Grow(20);
}
value.TryFormat(_unusedChars, out int written);
_unusedChars = _unusedChars.Slice(written);
}

public void Append<T>(T value)
{
if (value is string strVal)
{
Append(strVal);
}
else if(value is int intVal)
{
Append(intVal);
}
else if(value != null)
{
Append(value.ToString());
}
}*/
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Runtime.CompilerServices;

namespace Microsoft.Extensions.Logging
{
// ByReference<T> is meant to be used to represent "ref T" fields. It is working
// around lack of first class support for byref fields in C# and IL. The JIT and
// type loader has special handling for it that turns it into a thin wrapper around ref T.
internal struct ByReference<T>
{
private IntPtr _value;

public ByReference(ref T value)
{
// TODO-SPAN: This has GC hole. It needs to be JIT intrinsic instead
unsafe { _value = (IntPtr)Unsafe.AsPointer(ref value); }
}

public ref T Value
{
get
{
// TODO-SPAN: This has GC hole. It needs to be JIT intrinsic instead
unsafe { return ref Unsafe.As<IntPtr, T>(ref *(IntPtr*)_value); }
}
}
}
}
Loading