Skip to content

1. Diol backend service

Chingiz Olzhabaev edited this page Aug 14, 2024 · 4 revisions

Introduction

Still in progress! Don't use it for your production!

DiolBackendService is an aspnet application which contains a logic how to read, parse and group events from a dotnet application.

You may want to use the project in case if you need DIOL behavior but for your own UX.

The project is designed to be a web service, because an user may want to create their own UX on non-dotnet environment.

Basinc information

# Title Description
1 Name DiolBackendService
2 Link Project link
3 dotnet version net 8
4 Project type asp.net
5 Communication SignalR
6 Distribution as a dotnet tool

Dependencies

Internal

# Name Description
1 Diol.Share Contains DTO and basic contracts
2 Diol.Core Contains basic logic of logs processing
3 Diol.Aspnet Logic for asp.net related things

External

# Name License
1 Microsoft.Diagnostics.NETCore.Client MIT
2 Microsoft.Diagnostics.Tracing.TraceEvent MIT

DEMO run

DiolBackendService provides a page where you can be used as an example of using DiolBackendService.

To run a demo please follow next steps:

  1. Navigate to DiolBackendService
  2. Call dotnet build
  3. Call dotnet run
  4. New web app should opened in your browser
  5. Click connect
  6. Provide process id
  7. Click 'Start'
  8. Navigate to your project
  9. Make a request
  10. Check DiolBackendService page. In the table you should see your logs

How to install from Github Diol nuget feed

  1. Create a PAT token from github page with package:read permission
  2. Prepare user name
  3. Prepare your PAT
  4. Open setup.ps1 file from the repo
  5. Run the commands
# if you want to use the tool from nuget feed:
dotnet nuget add source --username <your_github_user_name> --password <your_pat> --name github-diol https://nuget.pkg.github.com/Dotnet-IO-logger/index.json

dotnet tool install -g DiolBackendService

How to install DiolBackendService locally

  1. Pull the repo
  2. Open the project folder
  3. Find setup.ps1
  4. Run commands from the script
  5. Congrats!

The commands will build DiolBackendService project and setup it as a dotnet tool which you can run from a terminal.

Now everything you need is:

# url is up to you
DiolBackendService --urls=http://localhost:62023/

How to get logs from DiolBackendService

Before starting please learn more information about aspnet signal r and chouse correct client version (js, C# and etc.). Documentation

We created an example for JS but it should be enough for implementing the same for other languages.

The whole source code of the example you may find here

1. Create a connection to LogsHub

const connection = new signalR.HubConnectionBuilder()
   .withUrl("/logsHub")
   .configureLogging(signalR.LogLevel.Information)
   .build();

2. Subscribe to LogRecieved

function logsReceivedHanndler(categoryName, eventName, dataAsJson) {
   // categoryName: ['HttpClient', 'AspnetCore', etc]
   // eventName: Dto name
   let data = JSON.parse(dataAsJson);
   console.info(categoryName, eventName, data );
}

connection.on('LogReceived', logsReceivedHanndler);

3. Connect to the SignalR hub

connection.start();

4. Start fetching logs from a dotnet process

let processId = <some_dotnet_process_id>;
connection.invoke('Subscribe', processId);

Hubs metadata

Hub info

Property Value Description
1 Name LogsHub
2 Type Hub
3 Url /logsHub
4 Link Link

Hub actions

# Name Arguments Description
1 GetProcesses message: string? Ask from the server a list with dotnet processes. The result will be sended as an event 'ProcessesReceived'
2 Subscribe processId: int Start processing a dotnet process. In client side you will recieve 'ProcessingStarted' event.

Hub events

You can find all events and dtos in the repo

# Name Result Description
1 ProcessesReceived dotnet process ids: int[] Returns the list of active dotnet process ids on your PC
2 ProcessingStarted processId: int Returns id of dotnet process DIOL has started to read logs
3 ProcessingFinished processId: int Returns id of dotnet process DIOL has completed to read logs
4 LogReceived LogReceived Event Triggered every time when new log comes

LogReceived Event

This event happen every time when the process recieve logs.

Structure

# Name Type Description
1 CategoryName string Represents a category: [HttpClient, AspnetCore, EntityFramework etc.]
2 EventName string Represents an event name and it is DTO name as well.
3 Data object data as json string

Logs Events

Categories

# Name Events Link Description
1 HttpClient RequestPipelineStartDto , RequestPipelineRequestHeaderDto , RequestPipelineEndDto, RequestPipelineResponseHeaderDto Models Events from HttpClient
2 AspnetCore RequestLogDto, RequestBodyDto, ResponseLogDto, ResponseBodyDto Models Works both for controllers and minimal api
3 EntityFramework ConnectionOpeningDto, CommandExecutingDto, CommandExecutedDto Models Events from EntityFramework
4 WebSockets (coming soon) x x x
5 gRPC (comming soon) x x x

Troubleshooting

If for some reasons you don't see logs, please double check that loggers are setup correctly on your application side (read here).

From your side you need to double check that:

  1. Coresponding loggers are setup.
  2. You changed appsettings.development.json file correctly.