# Llama Logger

## NuGet Package Details

**Package Name**

[Llamachant.ExpressApp.LlamaLogger](https://www.nuget.org/packages/Llamachant.ExpressApp.LlamaLogger)

## Overview

Llama Logger is a centralized error logging service designed to help developers track and manage exceptions across all their projects. By consolidating error logs into a single platform, it eliminates the need to manually access server log files, streamlining the debugging process.

### 🌟 Key Features

- [Custom Data](/content/docs/Llamachant.ExpressApp.LlamaLogger#CustomData/index.html)
- [Attachments](/content/docs/Llamachant.ExpressApp.LlamaLogger#Attachments/index.html)
- [Customize Entries](/content/docs/Llamachant.ExpressApp.LlamaLogger#CustomizeEntries/index.html)

#### TIP:

In order to utilize this module, you must have a Llama Logger account set up. If you don't have Llama Logger, create a free account at [www.llamalogger.com](https://www.llamalogger.com/)

## Installation

### Step 1: Install the Module
```
Install-Package 'Llamachant.ExpressApp.LlamaLogger'
```

### Step 2: Setup Using your Project API Key  
In your program.cs file, use LlamaLoggerTracing.Setup and LlamaLoggerTracing.Initialize along with your project API key and application version number to set up error logging.

**Example:**
```
 public static int Main(string[] args) {
    string version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
    LlamaLoggerTracing.Setup("{your_api_key}", version);
    LlamaLoggerTracing.Initialize();
}
```

## Adding Custom Data

It’s often helpful to have more context around an exception when it occurs. Llama Logger allows you to include custom data (text) to your exceptions (Standard subscription or higher required). You can add custom data globally and/or per-exception.

### Adding Custom Data Globally
```
LlamaLoggerClient client = new LlamaLoggerClient(apikey, version);
client.AddCustomData("Server", "Server001"); //This data will be included with every exception
```

### Adding Custom Data Per-Exception
```
LlamaLoggerClient client = new LlamaLoggerClient(apikey, version);
client.CustomizeLogEntry += Client_CustomizeLogEntry;

void Client_CustomizeLogEntry(object? sender, LlamaLogger.Core.CustomEventArgs.CustomizeLogEntryEventArgs e)
{
    e.LogEntry.AddCustomData("UserName", "Admin"); //This data will be included with this exception only
    e.LogEntry.AddCustomData("IP Address", "10.0.0.1"); //This data will be included with this exception only
}
```

## Adding Attachments

Llama Logger allows you to include attachments with your exceptions (Standard subscription or higher required). Attachments can be added per-exception and should be kept small as they count towards your monthly data transfer limit.

### Adding Attachments Per-Exception
```
LlamaLoggerClient client = new LlamaLoggerClient(apikey, version);
client.CustomizeLogEntry += Client_CustomizeLogEntry;

void Client_CustomizeLogEntry(object? sender, LlamaLogger.Core.CustomEventArgs.CustomizeLogEntryEventArgs e)
{
    byte[] screenshot = GetScreenshotData(); //Get an array of data from your choosing
    e.LogEntry.AddAttachment("Screenshot.png", screenshot);
}

byte[] GetScreenshotData() {}
```

## Customize Entries

Before entries are sent, you can customize them using the CustomizeLogEntry event. This is an opportunity to modify information, provide additional context, or cancel the exception upload.

### Ignore all exceptions of a particular type
```
LlamaLoggerClient client = new LlamaLoggerClient(apikey, version);
client.AddIgnoredExceptionType<ValidationException>();
```

### Ignore exceptions per-occurrence
```
LlamaLoggerClient client = new LlamaLoggerClient(apikey, version);
client.CustomizeLogEntry += Client_CustomizeLogEntry;

void Client_CustomizeLogEntry(object? sender, LlamaLogger.Core.CustomEventArgs.CustomizeLogEntryEventArgs e)
{
    if (e.LogEntry.Exception is InvalidOperationException ex && ex.Message.Contains("test"))
        e.Cancel = true; //This prevents the exception from being sent to Llama Logger
}
}
```

### More Features

For documentation on more advanced features, subscription details, and to see a walkthrough of the UI features and Organization/Project setup, please visit the Llama Logger site [Here.](https://llamalogger.com/)
