Configuration

Abstracts

Applications based on this frameworks requires to be configured using an settings.json file that will contains sections that defines the application desired configuration.

Settings.json file

The settings.json file can contains the following sections:

This file should contains all the different secciones following the rules of a json syntax as in the following example.

                
        {
            "ConnectionStrings": { ... },
            "ApplicationContext": { ... },
            "Cryptography": { ... },
            "Diagnostics": { ... }
        }
                

Connection strings

Connection strings are configured as the standard .NET Core configuration.

The connection string names (AuditDataAccessAPI and SecurityDataAccessAPI in the following example) must match the name os the DataAccessAPI objects defined within the application context.

                
        { 
            "ConnectionStrings": { 
                "AuditDataAccessAPI": "Data Source=<server-name-or-ip>;Initial Catalog= <catalog-name>;Integrated Security=True;Persist Security Info=false", 
                "SecurityDataAccessAPI": "Data Source=<server-name-or-ip>;Initial Catalog=<catalog-name>;Integrated Security=True;Persist Security Info=false" 
            }
        }
                

Application context

The application context section configures the Inetdev Framework Application Context by pointing the application to the folder where the context configuration files are stored.

This configuration is optional as the application context can be configured entirely from within the application libraries.

                
        { 
            "ApplicationContext": { 
                "Path": "<path-to-a-folder-with-context-config-files>" 
            } 
        }
                

Cryptography

The cryptography sections allows to configured the cryptography functionality from Inetdev.Security.Cryptography.

                
        { 
            "Cryptography": { 
                "AsymmetricKeyFileName": "<asymmetric-key-file-name>",
                "HashAlgorithmType": "", 
                "HashAlgorithmSaltEnabled": true, 
                "SymmetricAlgorithmType": "", 
                "SymmetricAlgorithmKeyFileName": "<symmetric-key-file-name>",
                "PreviousSymmetricAlgorithmKeyFileName": "<previous-symmetric-key-file-name>"
            } 
        }
                
This configures the cryptography sub-system to use: SHA1Manage as a hash algorithm for hashing and RijndaelManaged as a symmetric algorithm for encryption.

Diagnostics

This section configures the Inetdev.Diagnostics sub-system.

                
        {
            "Diagnostics": {
                "MinimumLevel": "None",
                "DefaultCategory": "Basic",
                "LogWriterProviderType": null,
                "Formatters": [
                    {
                        "Type": "Inetdev.Diagnostics.Formatters.TextLogFormatter, Inetdev, Version=1.0.0.0, Culture=Neutral, PublicKeyToken=856a2402e38a9992",
                        "Name": "TextLogFormatter",
                        "Header": "Level|Timestamp|Message {newline}",
                        "Template": "{level}|{timestamp}|{message} {newline}"
                    }
                ],
                "TraceTargets": [
                    {
                        "Type": "Inetdev.Diagnostics.TraceTargets.FlatFileTraceTarget, Inetdev, Version=1.0.0.0, Culture=Neutral, PublicKeyToken=856a2402e38a9992",
                        "Name": "Debug",
                        "Formatter": "TextLogFormatter",
                        "FileName": "%SystemDrive%\\Path\\Path\\FileName.Dbg-yyyy-MM-dd.log",
                        "TimestampPattern": "yyyy-MM-dd"
                    }
                ],
                "LogTargets": [
                    {
                        "Category": "Basic",
                        "TraceTargets": [ "Debug" ]
                    },
                    {
                        "Category": "Error",
                        "TraceTargets": [ "Debug" ]
                    },
                    {
                        "Category": "Debug",
                        "TraceTargets": [ "Debug" ]
                    },
                    {
                        "Category": "Warning",
                        "TraceTargets": [ "Debug" ]
                    },
                    {
                        "Category": "Process",
                        "TraceTargets": [ "Debug" ]
                    },
                    {
                        "Category": "Security",
                        "TraceTargets": [ "Debug" ]
                    }
                ]
            }
        }
                

Diagnostics configuration options

MinimumLevel

Configures the minimum level of log entries that are written to the log file. MinimumLevel options are:

  • Debug
  • Verbose
  • Information
  • Warning
  • Error
  • Critical
  • None (completely disables logging)
DefaultCategory

The default category assigned to log entries that does not has a category.

LogWriterProviderType

The type of a class that inherits from Inetdev.Diagnostics.LogWriterProvider and overrides the Create method (optional).

Formatters

An array of Formatters that formats log entries (at least one is required).

The code sample shows the configuration of the formatter provided by the Framework, the template option can contain this placeholders:

  • {level}: log entry level (Debug, Verbose, etc.).
  • {timestamp}: time of the event.
  • {timestamputc}: time of the event in UTC format.
  • {message}: log entry message or text.
  • {category}: category of the log entry.
  • {eventid}: identification of the event.
  • {eventname}: name of the event
  • {activityid}: identification of the activity.
  • {stopwatch}: Stopwatch information (timing)
  • {tenantname}: name of the current tenant.
  • {date}: date of the event.
  • {appdomain}: information of the application domain.
  • {threadid}: current thread id.
  • {threadname}: current thread name.
  • {newline}: a new line character.
  • {tab}: a tab character.
TraceTargets

An array of TraceTargets that configures where the log file(s) are written.

LogTargets

An array of LogTargets that configures to which TraceTargets are the log entries written to, based on their categories.

Startup code

At application startup configuration for Application Context, Diagnostics and Cryptography must be loaded and assigned to the corresponding objects as shown in the following code.

                    
        using Microsoft.Extensions.Configuration;
        using Inetdev.Context;
        using Inetdev.Diagnostics;
        using Inetdev.Security.Cryptography;

        namespace ApplicationNamespace
        {
            static class Startup
            {
                public static void Configure()
                {
                    var configuration = new ConfigurationBuilder()
                        .SetBasePath(@"drive:\path")
                        .AddJsonFile(@"settings.json", optional: false, reloadOnChange: true)
                        .Build();

                    Logger.Configuration = configuration;
                    Cryptographer.Configuration = configuration;
                    ApplicationContext.Configuration = configuration;
                }
            }
        }
                
Top