Skip to content

Commit

Permalink
Add XML documentation to extensions.
Browse files Browse the repository at this point in the history
  • Loading branch information
mo-esmp committed May 28, 2021
1 parent e13f798 commit b11364e
Show file tree
Hide file tree
Showing 12 changed files with 160 additions and 33 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
A simple Serilog log viewer for following sinks:
- [Serilog.Sinks.MSSqlServer](https://github.com/serilog/serilog-sinks-mssqlserver)
- [Serilog.Sinks.MySql](https://github.com/TeleSoftas/serilog-sinks-mariadb)
- [Serilog.Sinks.Postgresql](https://github.com/b00ted/serilog-sinks-postgresql),
- [Serilog.Sinks.MongoDB](https://github.com/serilog/serilog-sinks-mongodb)
- [Serilog.Sinks.ElasticSearch](https://github.com/serilog/serilog-sinks-elasticsearch)
- [Serilog.Sinks.Postgresql](https://github.com/b00ted/serilog-sinks-postgresql)
- [Serilog.Sinks.MongoDB](https://github.com/serilog/serilog-sinks-mongodb)
- [Serilog.Sinks.ElasticSearch](https://github.com/serilog/serilog-sinks-elasticsearch)

![serilog ui](https://raw.githubusercontent.com/mo-esmp/serilog-ui/master/assets/serilog-ui.jpg)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,19 @@

namespace Serilog.Ui.ElasticSearchProvider
{
/// <summary>
/// ElasticSearch data provider specific extension methods for <see cref="SerilogUiOptionsBuilder"/>.
/// </summary>
public static class SerilogUiOptionBuilderExtensions
{
/// <summary>
/// Configures the SerilogUi to connect to a MongoDB database.
/// </summary>
/// <param name="optionsBuilder"> The options builder. </param>
/// <param name="endpoint"> The url of ElasticSearch server. </param>
/// <param name="indexName"> Name of the log index. </param>
/// <exception cref="ArgumentNullException"> throw if endpoint is null </exception>
/// <exception cref="ArgumentNullException"> throw is indexName is null </exception>
public static void UseElasticSearchDb(this SerilogUiOptionsBuilder optionsBuilder, Uri endpoint, string indexName)
{
if (endpoint == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,21 @@

namespace Serilog.Ui.MongoDbProvider
{
/// <summary>
/// MongoDB data provider specific extension methods for <see cref="SerilogUiOptionsBuilder"/>.
/// </summary>
public static class SerilogUiOptionBuilderExtensions
{
/// <summary>
/// Configures the SerilogUi to connect to a MongoDB database.
/// </summary>
/// <param name="optionsBuilder"> The options builder. </param>
/// <param name="connectionString"> The connection string. </param>
/// <param name="databaseName"> Name of the data table. </param>
/// <param name="collectionName"> Name of the collection name. </param>
/// <exception cref="ArgumentNullException"> throw if connectionString is null </exception>
/// <exception cref="ArgumentNullException"> throw is databaseName is null </exception>
/// <exception cref="ArgumentNullException"> throw is collectionName is null </exception>
public static void UseMongoDb(
this SerilogUiOptionsBuilder optionsBuilder,
string connectionString,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,22 @@

namespace Serilog.Ui.MsSqlServerProvider
{
/// <summary>
/// SQL Server data provider specific extension methods for <see cref="SerilogUiOptionsBuilder"/>.
/// </summary>
public static class SerilogUiOptionBuilderExtensions
{
/// <summary>
/// Configures the SerilogUi to connect to a SQL Server database.
/// </summary>
/// <param name="optionsBuilder"> The options builder. </param>
/// <param name="connectionString"> The connection string. </param>
/// <param name="tableName"> Name of the table. </param>
/// <param name="schemaName">
/// Name of the table schema. default value is <c> dbo </c>
/// </param>
/// <exception cref="ArgumentNullException"> throw if connectionString is null </exception>
/// <exception cref="ArgumentNullException"> throw is tableName is null </exception>
public static void UseSqlServer(
this SerilogUiOptionsBuilder optionsBuilder,
string connectionString,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,11 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Serilog.Ui.Core\Serilog.Ui.Core.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="Extensions\" />
<PackageReference Include="Dapper" Version="2.0.35" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="2.1.1" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Dapper" Version="2.0.35" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="2.1.1" />
<ProjectReference Include="..\Serilog.Ui.Core\Serilog.Ui.Core.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Serilog.Ui.Core;
using System;

namespace Serilog.Ui.MySqlProvider.Extensions
namespace Serilog.Ui.MySqlProvider
{
/// <summary>
/// MySQL data provider specific extension methods for <see cref="SerilogUiOptionsBuilder"/>.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
using System;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using Serilog.Ui.Core;
using System;

namespace Serilog.Ui.PostgreSqlProvider.Extensions
namespace Serilog.Ui.PostgreSqlProvider
{
/// <summary>
/// PostgreSQL data provider specific extension methods for <see cref="SerilogUiOptionsBuilder"/>.
/// </summary>
public static class SerilogUiOptionBuilderExtensions
{
/// <summary>
/// Configures the SerilogUi to connect to a PostgreSQL database.
/// </summary>
/// <param name="optionsBuilder"> The options builder. </param>
/// <param name="connectionString"> The connection string. </param>
/// <param name="tableName"> Name of the table. </param>
/// <param name="schemaName">
/// Name of the table schema. default value is <c> public </c>
/// </param>
/// <exception cref="ArgumentNullException"> throw if connectionString is null </exception>
/// <exception cref="ArgumentNullException"> throw is tableName is null </exception>
public static void UseNpgSql(
this SerilogUiOptionsBuilder optionsBuilder,
string connectionString,
Expand Down
38 changes: 38 additions & 0 deletions src/Serilog.Ui.Web/Extensions/ApplicationBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using System;

namespace Serilog.Ui.Web
{
/// <summary>
/// Contains extensions for configuring routing on an <see cref="IApplicationBuilder"/>.
/// </summary>
public static class ApplicationBuilderExtensions
{
/// <summary>
/// Adds a <see cref="SerilogUiMiddleware"/> middleware to the specified <see cref="IApplicationBuilder"/>.
/// </summary>
/// <param name="applicationBuilder">
/// The <see cref="IApplicationBuilder"/> to add the middleware to.
/// </param>
/// <param name="options"> The options to configure SerilogUI dashboard. </param>
/// <returns> IApplicationBuilder. </returns>
/// <exception cref="ArgumentNullException"> throw if applicationBuilder if null </exception>
public static IApplicationBuilder UseSerilogUi(this IApplicationBuilder applicationBuilder, Action<UiOptions> options = null)
{
if (applicationBuilder == null)
throw new ArgumentNullException(nameof(applicationBuilder));

var uiOptions = new UiOptions();
options?.Invoke(uiOptions);

var scope = applicationBuilder.ApplicationServices.CreateScope();
var authOptions = scope.ServiceProvider.GetService<AuthorizationOptions>();
uiOptions.AuthType = authOptions.AuthenticationType.ToString();

scope.Dispose();

return applicationBuilder.UseMiddleware<SerilogUiMiddleware>(uiOptions);
}
}
}
19 changes: 19 additions & 0 deletions src/Serilog.Ui.Web/Extensions/AuthorizationOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,33 @@

namespace Serilog.Ui.Web
{
/// <summary>
/// The options to be used by SerilogUI to log access authorization.
/// </summary>
public class AuthorizationOptions
{
/// <summary>
/// Gets or sets the type of the authentication.
/// </summary>
/// <value> The type of the authentication. </value>
public AuthenticationType AuthenticationType { get; set; }

/// <summary>
/// Gets or sets the authorized usernames.
/// </summary>
/// <value> The usernames. </value>
public IEnumerable<string> Usernames { get; set; }

/// <summary>
/// Gets or sets the authorized roles.
/// </summary>
/// <value> The roles. </value>
public IEnumerable<string> Roles { get; set; }

/// <summary>
/// Gets or sets a value indicating whether this <see cref="AuthorizationOptions"/> is enabled.
/// </summary>
/// <value> <c> true </c> if enabled; otherwise, <c> false </c>. </value>
internal bool Enabled { get; set; } = false;
}

Expand Down
33 changes: 14 additions & 19 deletions src/Serilog.Ui.Web/Extensions/SerilogUiOptionBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using Serilog.Ui.Core;
using System;

namespace Serilog.Ui.Web
{
/// <summary>
/// Extension methods for <see cref="SerilogUiOptionsBuilder"/>.
/// </summary>
public static class SerilogUiOptionBuilderExtensions
{
/// <summary>
/// In order to give appropriate rights for production use, you need to enables
/// configuring authorization. By default only local requests have access to the log
/// dashboard page.
/// </summary>
/// <param name="optionsBuilder"> The builder being used to configure the SerilogUI. </param>
/// <param name="options"> An action to allow configure authorization. </param>
/// <returns> SerilogUiOptionsBuilder. </returns>
/// <exception cref="ArgumentNullException"> Throw if optionsBuilder is null </exception>
/// <exception cref="ArgumentNullException"> Throw if options is null </exception>
public static SerilogUiOptionsBuilder EnableAuthorization(this SerilogUiOptionsBuilder optionsBuilder, Action<AuthorizationOptions> options)
{
if (optionsBuilder == null)
Expand All @@ -22,22 +34,5 @@ public static SerilogUiOptionsBuilder EnableAuthorization(this SerilogUiOptionsB

return optionsBuilder;
}

public static IApplicationBuilder UseSerilogUi(this IApplicationBuilder applicationBuilder, Action<UiOptions> options = null)
{
if (applicationBuilder == null)
throw new ArgumentNullException(nameof(applicationBuilder));

var uiOptions = new UiOptions();
options?.Invoke(uiOptions);

var scope = applicationBuilder.ApplicationServices.CreateScope();
var authOptions = scope.ServiceProvider.GetService<AuthorizationOptions>();
uiOptions.AuthType = authOptions.AuthenticationType.ToString();

scope.Dispose();

return applicationBuilder.UseMiddleware<SerilogUiMiddleware>(uiOptions);
}
}
}
13 changes: 13 additions & 0 deletions src/Serilog.Ui.Web/Extensions/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,21 @@

namespace Serilog.Ui.Web
{
/// <summary>
/// Extension methods for setting up SerilogUI related services in an <see cref="IServiceCollection"/>.
/// </summary>
public static class ServiceCollectionExtensions
{
/// <summary>
/// Registers the SerilogUI as a service in the <see cref="IServiceCollection"/>.
/// </summary>
/// <param name="services"> The services. </param>
/// <param name="optionsBuilder">
/// An action to configure the <see cref="SerilogUiOptionsBuilder"/> for the SerilogUI.
/// </param>
/// <exception cref="ArgumentNullException"> services </exception>
/// <exception cref="ArgumentNullException"> optionsBuilder </exception>
/// <returns> The same service collection so that multiple calls can be chained. </returns>
public static IServiceCollection AddSerilogUi(this IServiceCollection services, Action<SerilogUiOptionsBuilder> optionsBuilder)
{
if (services == null)
Expand Down
14 changes: 14 additions & 0 deletions src/Serilog.Ui.Web/Extensions/UiOptions.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
namespace Serilog.Ui.Web
{
/// <summary>
/// The options to be used by SerilogUI to configure log dashboard. You normally use a <see
/// cref="Core.SerilogUiOptionsBuilder"/> to create instances of this class.
/// </summary>
public class UiOptions
{
/// <summary>
/// Gets or sets the route prefix to access log dashboard via browser. The default value
/// is <c> serilog-ui </c> and you can the dashboard by using <c>
/// http://localhost/serilog-ui </c>
/// </summary>
/// <value> The route prefix. </value>
public string RoutePrefix { get; set; } = "serilog-ui";

/// <summary>
/// Gets or sets the type of the authentication.
/// </summary>
/// <value> The type of the authentication. </value>
internal string AuthType { get; set; }
}
}

0 comments on commit b11364e

Please sign in to comment.