Latest version 1.0.0-beta17
Razorsharp APM CLI is a cutting-edge performance monitoring and analysis tool designed for .NET applications. It allows developers to easily identify performance bottlenecks, monitor resource usage, and detect unhandled errors in real-time, enhancing application reliability and efficiency.
Disclaimer: Please note that Razorsharp APM CLI is currently in beta. It is recommended to use it only in test environments at this stage. By using Razorsharp APM CLI, you acknowledge and agree that the tool is provided "as is" without warranty of any kind, express or implied. We do not accept liability for any direct, indirect, incidental, special, exemplary, or consequential damages arising from the use of the software. Please read license i nuget package for further details.
To install Razorsharp APM CLI, you need the .NET SDK installed on your machine. Once you have the SDK, open your terminal or command prompt and execute the following command to install Razorsharp APM CLI globally:
dotnet tool install Razorsharp.APM.CLI --global --version 1.0.0-beta*
This command makes Razorsharp APM CLI available globally on your system, enabling you to use it from any directory.
Using Razorsharp APM CLI is straightforward. After installation, you can start monitoring your .NET application by injecting Razorsharp APM into your entry assembly. Open your terminal or command prompt and execute the following command:
razorsharp --inject HelloWorld.dll
Replace HelloWorld.dll
with the DLL file of your .NET application's entry assembly. This command injects Razorsharp APM's monitoring capabilities into your application, allowing you to track method calls, resource usage, and other critical performance metrics.
While this step is optional, configuring the log destination enhances flexibility by allowing Razorsharp logs to be integrated with third-party solutions for processing.
To customize the storage location for log files, incorporate a apm.profiler.json
file into your project with the configuration outlined below:
{
"LogProviders": [
{
"Name": "OpenTelemetry",
"Enabled": true,
"Configuration": {
"Endpoint": "http://localhost:4317",
"ServiceName": "my-app"
}
},
{
"Name": "AzureBlob",
"Enabled": false,
"Configuration": {
"ConnectionString": "DefaultEndpointsProtocol=https;AccountName=YourAccountName;AccountKey=YourAccountKey;EndpointSuffix=core.windows.net",
"ContainerName": "logentries"
}
},
{
"Name": "LocalDisk",
"Enabled": false,
"Configuration": {
"Path": "c:\\logs"
}
}
],
"excludeLogStart": true
}
The configuration supports having only one log provider enabled at any given time, defaulting to the first one with "Enabled": true
.
Without any explicit enabling, LocalDisk
is used by default, with the path set to c:\\logs
on Windows or /var/log/razorsharp
on Linux systems.
The option "excludeLogStart": true
is relevant to the LocalDisk and AzureBlob log providers and aims to reduce log volume, which can be beneficial for debugging long running code.
Razorsharp Guard provides essential defenses against potential SQL injection threats by monitoring SQL queries in real-time. It's configured to help you manage how these threats are handled once detected.
By default, Razorsharp Guard is set to log a warning when it detects suspicious SQL queries, which allows you to review potential threats without interrupting the application's operations. Additionally, you have the option to escalate the response to a more proactive approach:
{
"Guard": {
"SqlInjection": {
"Enabled": true,
"OnDetection": "ThrowException"
}
}
}
In the configuration shown above, the OnDetection
setting is adjusted to ThrowException
. This setting not only logs the incident but also throws an exception and prevents the suspicious SQL query from being executed on the SQL server. This ensures immediate action is taken to secure your application against possible database attacks, enhancing your overall security posture.
To use Razorsharp APM CLI in a Docker environment, ensure your .csproj file is properly configured for optimal integration. This is particularly crucial for ensuring functionality in development modes such as debugging in Visual Studio.
This configuration is essential if you aim to utilize Razorsharp APM CLI during debug sessions in Visual Studio.
Without this setting, Visual Studio optimizes the build process in a way that excludes the integration of Razorsharp APM CLI.
To ensure Razorsharp APM CLI functions correctly when debugging with Docker in Visual Studio, add the following to your .csproj file:
<PropertyGroup>
<ContainerDevelopmentMode>Regular</ContainerDevelopmentMode>
</PropertyGroup>
Implementing this configuration allows Razorsharp APM CLI to be activated during Visual Studio debug sessions, offering a comprehensive development experience with full access to its features. This setting is not necessary for release mode deployments.
# Define a publish stage
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS publish
WORKDIR /src
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "HelloWorld.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
# Install Razorsharp.APM.CLI tool and run it
RUN dotnet tool install Razorsharp.APM.CLI --global --version 1.0.0-beta*
ENV PATH="${PATH}:/root/.dotnet/tools"
RUN razorsharp --inject /app/publish/HelloWorld.dll
# Define a custom debug stage
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS debug
WORKDIR /app
EXPOSE 80
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "HelloWorld.dll"]
This Dockerfile example demonstrates the setup for deploying your Dockerized .NET application with Razorsharp APM CLI integrated for performance monitoring.