---
title: Hello World Log Event Sample (C#) – Quick Start with Nodinite Log API
description: Step-by-step C# tutorial for logging Nodinite Log Events. Learn how to create, validate, and write Log Events using the Log API, with code samples, NuGet setup, and integration with Pickup Service.
---

# Hello World Log Event sample (C#)

Get started quickly with :Nodinite: logging by following this hands-on C# tutorial. Learn how to create, validate, and write [Log Events][Log Event] using the Log API, and discover how to integrate with the [Pickup Service][] for robust, asynchronous logging.

What you'll find on this page:

* ✅ Step-by-step C# sample for logging with the Log API  
* ✅ How to use NuGet to add Nodinite libraries  
* ✅ Full code examples for creating and validating Log Events  
* ✅ Integration with Pickup Service for asynchronous delivery  
* ✅ Best practices for reusable, configurable logging  

## :fa-lightbulb: Recommended Approach: Use Appenders

>[!TIP]
>**There are multiple ways to create Nodinite Log Events:**
>
> * **:fa-star: Recommended for .NET (.NET Core, .NET 5+, .NET 6+):** [Serilog][] with Nodinite sinks
>   * Native integration with modern .NET logging
>   * Minimal code changes to existing applications
>   * Built-in structured logging support
>   * Multiple sinks available: [Log API][Serilog Log API], [Event Hub][Serilog Event Hub], [Service Bus][Serilog ServiceBus], [File][Serilog File], [Blob Storage][Serilog Blob Storage]
>
> * **:fa-star: Recommended for .NET Framework 4.8:** [Log4Net Appender][]
>   * Seamless integration with existing Log4Net applications
>   * Proven stability for .NET Framework workloads
>   * Configuration-based setup with minimal code changes
>
> * **Direct NuGet Package (this article):** Manual log event creation
>   * Full control over log event structure
>   * Useful for custom logging scenarios
>   * Requires more code for each log entry
>   * Best for edge cases or non-.NET integration

**This article demonstrates the direct NuGet package approach** without using appenders. Use this method when you need full control over the log event creation process or when integrating from non-.NET systems that can generate JSON.

>:fa-file-archive: If you want to get started even faster, download the [FileWriterSample](http://download.integrationsoftware.se/Samples/Log%20Agent/IM.LogAgent.FileWriterSample.zip)<sup>:fa-arrow-up-right-from-square:</sup> to use with the [Pickup Log Events Service Logging Agent][Pickup Service]

<div class="mermaid">
graph LR
    roProject(1. Create new Project)-->roNuGet(2. Add NuGet reference)
    roNuGet --> roCustomCode(3. Set Log Event Properties)
    roCustomCode --> ro(4. Write Event)
</div>  

*Illustration: Steps to create, configure, and write a Log Event in C# using the Nodinite Log API.*

>Please review the [Asynchronous Logging][] user guide if you have not already read it.

If you are not a .NET developer, you can use any programming language. The goal is to produce a [JSON based Log Event][JSON Log Event].

## :fa-forward-step: Step 1: Create a new Visual Studio Project

From Visual Studio, create a **new Project** (we recommend creating a **library** for reusable code)  
![Create New Project][1]  
*Create New Project*

>Make sure to select .NET Framework 4.8 or later  

## :fa-forward-step: Step 2: Add NuGet package reference

:Nodinite: provides multiple libraries and samples on GitHub and NuGet. For this sample, use **Nodinite.Libraries.[Contracts][].LogRestApi** from [NuGet](https://www.nuget.org/packages/)<sup>:fa-arrow-up-right-from-square:</sup>:

* :fa-box-full: [Nodinite.Libraries.Contracts.LogRestApi](https://www.nuget.org/packages/Nodinite.Libraries.Contracts.LogRestApi)<sup>:fa-arrow-up-right-from-square:</sup>
  * [MIT License](https://download.nodinite.com/public/MIT-LICENSE.txt)<sup>:fa-arrow-up-right-from-square:</sup>

1. In your project, right-click the **solution** and select **Manage NuGet Packages...**  
   ![Add NuGet package reference][4]  
   *Example of accessing Manage NuGet Packages in Visual Studio.*  
1. Click the **settings icon** to configure package sources if needed  
   ![Package Manager Settings][2]  
   *Example of Package Manager Settings for configuring NuGet sources.*  
1. If the Nodinite package source is not already configured, add it as a package source  
   ![Nodinite Package Source][3]  
   *Example of adding the Nodinite package source configuration.*  
1. Add a NuGet Reference to **Nodinite.Libraries.Contracts.LogRestApi**  
   ![Nodinite.Libraries.Contracts.LogRestApi][5]  
   *Example of selecting the Nodinite.Libraries.Contracts.LogRestApi package.*  

Click the **Install** button to add the library to your selected project(s).

>If you are using :Nodinite:, use version 5.x or later. For Integration Manager, use version 4.x.

## :fa-forward-step: Step 3: Add custom code

You will now create the [Log Event][].

The [Log Event][] has three distinct parts:

1. Event details (some mandatory fields)
2. Payload (optional)
3. Context properties (optional)

<div class="mermaid">
graph TD
    subgraph "Log Event"
        subgraph "1. Details"
            roED[fal:fa-bolt Event Details </br>LogDateTime = 2018-05-03 13:37:00+02:00</br> EndPointName = https://api.nodinite.com/... </br> MessageType=Invoice </br>...]
        end
        subgraph "2. Payload"
            ro[fal:fa-envelope Message</br>Body=base64EncodedMessage]
        end
        subgraph "3. Context Properties"
            roKey[fal:fa-key Key Values </br>InvoiceNo = 123 </br>CorrelationId=456 </br>...]
        end
    end
</div>

*Illustration: Log Event structure with details, payload, and context properties in Nodinite.*

Now in Visual Studio, type **LogEvent** and add the appropriate using statement by pressing **CTRL** + **.** (dot).  

![Type Log Event][6]  
*Example of adding the using statement for LogEvent in Visual Studio.*  

### Create the LogEvent

Let's create a method that creates and returns the :Nodinite: [LogEvent][Log Event]:

```csharp
private LogEvent CreateNodiniteLogEvent()
{
    return new LogEvent()
    {                
    };
}
```

### Mandatory fields

You must provide the following **mandatory** fields (see the [JSON Log Event][] user guide for details):

```csharp
// Required values 
LogAgentValueId = 42,
EndPointName = "INT101: Receive Hello World Log Events",
EndPointUri = "C:\\temp\\in",
EndPointDirection = 0,
EndPointTypeId = LogEventEndPointType.File,
OriginalMessageTypeName = "Hello.World.File/1.0",  // CRITICAL: This determines Search Field extraction
LogDateTime = DateTime.UtcNow
```

> **Why `OriginalMessageTypeName` is critical:**
>
> The `OriginalMessageTypeName` field (or `MessageType`) tells Nodinite which [Search Field Expressions][] to run on your payload. Without a proper [Message Type][Message Types]:
>
> * Your business data (Order Numbers, Customer IDs, etc.) won't be extracted
> * You won't be able to search by business identifiers in [Log Views][]
> * [Non-Events Monitoring][] won't have the data it needs for alerts
> * [BPM][] won't be able to correlate transactions across process steps
>
> **Always set a meaningful Message Type** that has corresponding Search Field Expressions configured in Nodinite.
>
> Learn more: [Message Types][], [Search Fields][], [Log Event Processing][]

### Optional Fields example

Below is a fully populated [Log Event][] example:

```csharp
// Required values 
LogAgentValueId = 42,
EndPointName = "INT101: Receive Hello World Log Events",
EndPointUri = "C:\\temp\\in",
EndPointDirection = 0,
EndPointTypeId = LogEventEndPointType.File,
OriginalMessageTypeName = "Hello.World.File/1.0",
LogDateTime = DateTime.UtcNow,

// Optional values
EventDirection = LogEventEventDirection.ExternalIncoming,
ProcessingUser = "DOMAIN\\user",
SequenceNo = 0,
EventNumber = 0,
LogText = "File OK",
ApplicationInterchangeId = "",
LocalInterchangeId = null,
LogStatus = 0,
ProcessName = "My Process",
ProcessingMachineName = "localhost",
ProcessingModuleName = "INT101-HelloWorld-Application",
ProcessingModuleType = "FilePickup",
ServiceInstanceActivityId = null,
ProcessingTime = 80,

// Add Body (payload)
Body = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(new { orderid = "123", name = "John Doe" })),

// Add arbitrary Context
Context = new Dictionary<string, string> {
    { "CorrelationId", "064205E2-F7CF-43A6-B514-4B55536C2B67" },
    { DefaultContextProperties.Filename, "Hello.txt" }
}
```

### How do I validate a Log Event?

Use this sample method to validate your [Log Event][]:

```csharp
private static void ValidateLogEvent(LogEvent logEvent)
{
    if (!logEvent.IsValid(out List<LogReceiptErrorMessage> errorMessages))
    {
        Console.WriteLine("Log Event is not valid!");
        foreach (var errorMessage in errorMessages)
        {
            Console.WriteLine("{0}\\t\\t{1}", errorMessage.Title, errorMessage.Message);
        }
    }
    else
    {
        Console.WriteLine("Log Event OK!");
    }
}
```

### Create, Validate and write Log Event to file example

Below is the full example:

```csharp
using Nodinite.Libraries.Contracts.LogRestApi;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace Nodinite.Samples
{
    public class SampleLogEvent
    {
        private LogEvent CreateNodiniteLogEvent()
        {
            return new LogEvent()
            {
                // Required values 
                LogAgentValueId = 42,
                EndPointName = "INT101: Receive Hello World Log Events",
                EndPointUri = "C:\\temp\\in",
                EndPointDirection = 0,
                EndPointTypeId = LogEventEndPointType.File,
                OriginalMessageTypeName = "Hello.World.File/1.0",
                LogDateTime = DateTime.UtcNow,

                // Optional values
                EventDirection = LogEventEventDirection.ExternalIncoming,
                ProcessingUser = "DOMAIN\\user",
                SequenceNo = 0,
                EventNumber = 0,
                LogText = "File OK",
                ApplicationInterchangeId = "",
                LocalInterchangeId = null,
                LogStatus = 0,
                ProcessName = "My Process",
                ProcessingMachineName = "localhost",
                ProcessingModuleName = "INT101-HelloWorld-Application",
                ProcessingModuleType = "FilePickup",
                ServiceInstanceActivityId = null,
                ProcessingTime = 80,

                // Add Body (payload)
                Body = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(new { orderid = "123", name = "John Doe" })),

                // Add arbitrary Context
                Context = new Dictionary<string, string> {
                    { "CorrelationId", "064205E2-F7CF-43A6-B514-4B55536C2B67" },
                    { DefaultContextProperties.Filename, "Hello.txt" }
                }

            };
        }

        private void ValidateLogEvent(LogEvent logEvent)
        {
            if (!logEvent.IsValid(out List<LogReceiptErrorMessage> errorMessages))
            {
                Console.WriteLine("Log Event is not valid!");
                foreach (var errorMessage in errorMessages)
                {
                    Console.WriteLine("{0}\\t\\t{1}", errorMessage.Title, errorMessage.Message);
                }
            }
            else
            {
                Console.WriteLine("Log Event OK!");
            }
        }

        public void CreateValidateAndWriteLogEventToFile()
        {
            LogEvent logEvent = CreateNodiniteLogEvent();
            ValidateLogEvent(logEvent);

            string jsonString = logEvent.ToJson();

            using (StreamWriter file = File.CreateText(string.Format("LogEvent_{0}.json", Guid.NewGuid())))
            {
                file.WriteLine(jsonString);
            }
        }        
    }
}
```

>Make sure to customize the code snippet above according to your log needs. Avoid hard coding and use config files and/or parameters to dynamically set the properties.

The file written in the example above is intended to be consumed by the [Pickup Log Events Service Logging Agent][Pickup Service]. Make sure to read more in the [Asynchronous Logging][] user guide. To post the Log Event directly to the [Log API][LogAPI] instead, see [Log using REST][].

## :fa-hand-point-right: Next Steps

* :fa-cloud-arrow-down: [Log Api][LogAPI] - Log from code (C# and Java)  
* :fa-code: [Log using REST][] - Base URL, OAuth 2.0, and code samples  
* :fa-terminal: [Generate Log Events with PowerShell][Generate Log Events] - Batch generation and exception logging examples  
* :fa-bolt: [Log Event][]  
  * :fa-tags: [Context Options][]  
  * :fa-flag: [Log Status Codes][]  
  * :fa-arrows-left-right: [Event Directions][EventDirections]  
* :fa-sign-in-alt: [Endpoints][]  
  * :fa-plug: [Endpoint Types][EndpointTypes]  
  * [Endpoint Directions][]  

## :fa-link-horizontal: Related Topics

* :fa-file: [Message Types][]  
* :fa-box-archive: [Log Agents][] - Events and messages  
* :fa-hard-drive: [Logging Service][] - Processes (indexing) the messages  
* :fa-search: [Log Views][] - Manage [User][Users] access to events and messages across platform  
* :fa-database: [Log Databases][] - Keep as much data as you like  
* :fa-sitemap: [Repository Model][]  

[1]:{ndm}/Documentation%20Pictures/IM/CoreServices/LogAPI/SampleLogEvent/CreateNewProject.png
[2]:{ndm}/Documentation%20Pictures/IM/CoreServices/LogAPI/SampleLogEvent/PackageManagerSettings.png
[3]:{ndm}/Documentation%20Pictures/IM/CoreServices/LogAPI/SampleLogEvent/NodinitePackageSource.png
[4]:{ndm}/Documentation%20Pictures/IM/CoreServices/LogAPI/SampleLogEvent/ManageNuGetPackages.png
[5]:{ndm}/Documentation%20Pictures/IM/CoreServices/LogAPI/SampleLogEvent/SelectNuGetPackage.png
[6]:{ndm}/Documentation%20Pictures/IM/CoreServices/LogAPI/SampleLogEvent/TypeLogEvent.png

[Asynchronous Logging]:{ndr}/Core%20Services/Log%20API/Features/Asynchronous%20Logging.md
[BPM]:{ndr}/Repository%20Model/BPMs/Overview.md
[Context Options]:{ndr}/Core%20Services/Log%20Event/Features/Context%20Options.md
[Contracts]:{ndr}/Getting%20Started/4.%20Repository/Contracts/Overview.md
[Endpoint Directions]:{ndr}/Core%20Services/Log%20Event/Features/Endpoint%20Directions.md
[Endpoints]:{ndr}/Repository%20Model/Endpoints/Overview.md
[EndpointTypes]:{ndr}/Core%20Services/Log%20Event/Features/Endpoint%20Types.md
[EventDirections]:{ndr}/Core%20Services/Log%20Event/Features/Event%20Directions.md
[Generate Log Events]:{ndr}/Core%20Services/Log%20API/Troubleshooting/FAQ%20-%20Generate%20Log%20Events.md
[JSON Log Event]:{ndr}/Core%20Services/Log%20Event/Features/JSON%20Log%20Event.md
[Log Agents]:{ndr}/Administration/1.%20Log%20Management/3.%20Log%20Agents/Features/What%20is%20a%20Log%20Agent.md
[Log Databases]:{ndr}/Core%20Services/Log%20Databases/Overview.md
[Log Event]:{ndr}/Core%20Services/Log%20Event/Overview.md
[Log Event Processing]:{ndr}/Core%20Services/Log%20Event/Overview.md
[Log Status Codes]:{ndr}/Administration/1.%20Log%20Management/3.%20Log%20Agents/Features/What%20is%20a%20Log%20Status%20Code.md
[Log using REST]:{ndr}/Core%20Services/Log%20API/Features/Log%20using%20REST.md
[Log Views]:{ndr}/Administration/1.%20Log%20Management/1.%20Log%20Views/Features/What%20is%20a%20Log%20View.md
[Log4Net Appender]:{ndr}/Logging%20and%20Monitoring/Log4Net%20Appender/Overview.md
[LogAPI]:{ndr}/Core%20Services/Log%20API/Overview.md
[Logging Service]:{ndr}/Core%20Services/Logging%20Service/Overview.md
[Message Types]:{ndr}/Repository%20Model/Message%20Types/Overview.md
[Non-Events Monitoring]:{ndr}/Logging%20and%20Monitoring/Non-Events/Overview.md
[Pickup Service]:{ndr}/Logging%20and%20Monitoring/Pickup%20LogEvents%20Service/Overview.md
[Repository Model]:{ndr}/Repository%20Model/Overview.md
[Search Field Expressions]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Overview.md
[Search Fields]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/What%20is%20a%20Search%20Field.md
[Serilog]:{ndr}/Logging%20and%20Monitoring/Serilog/Overview.md
[Serilog Blob Storage]:{ndr}/Logging%20and%20Monitoring/Serilog/Features/Blob%20Storage.md
[Serilog Event Hub]:{ndr}/Logging%20and%20Monitoring/Serilog/Features/Event%20Hub.md
[Serilog File]:{ndr}/Logging%20and%20Monitoring/Serilog/Features/File.md
[Serilog Log API]:{ndr}/Logging%20and%20Monitoring/Serilog/Features/Log%20API.md
[Serilog ServiceBus]:{ndr}/Logging%20and%20Monitoring/Serilog/Features/ServiceBus.md
[Users]:{ndr}/Administration/3.%20Access%20Management/2.%20Users/Features/What%20is%20a%20User.md