---
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 <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> 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  

## <i class="fal fa-lightbulb" aria-hidden="true"></i> Recommended Approach: Use Appenders

<aside aria-label="Tip" class="nodinite-note nodinite-note--tip">
<p class="nodinite-note__label" aria-hidden="true"><i class="far fa-fw fa-lightbulb"></i> Tip</p>
<div class="nodinite-note__content"><p><strong>There are multiple ways to create Nodinite Log Events:</strong></p><ul>
<li>
<p><strong><i class="fal fa-star" aria-hidden="true"></i> Recommended for .NET (.NET Core, .NET 5+, .NET 6+):</strong> <a href="https://docs.nodinite.com/logging-and-monitoring/serilog/overview/">Serilog</a> with Nodinite sinks</p>
<ul>
<li>Native integration with modern .NET logging</li>
<li>Minimal code changes to existing applications</li>
<li>Built-in structured logging support</li>
<li>Multiple sinks available: <a href="https://docs.nodinite.com/logging-and-monitoring/serilog/features/log-api/">Log API</a>, <a href="https://docs.nodinite.com/logging-and-monitoring/serilog/features/event-hub/">Event Hub</a>, <a href="https://docs.nodinite.com/logging-and-monitoring/serilog/features/servicebus/">Service Bus</a>, <a href="https://docs.nodinite.com/logging-and-monitoring/serilog/features/file/">File</a>, <a href="https://docs.nodinite.com/logging-and-monitoring/serilog/features/blob-storage/">Blob Storage</a></li>
</ul>
</li>
<li>
<p><strong><i class="fal fa-star" aria-hidden="true"></i> Recommended for .NET Framework 4.8:</strong> <a href="https://docs.nodinite.com/logging-and-monitoring/log4net-appender/overview/">Log4Net Appender</a></p>
<ul>
<li>Seamless integration with existing Log4Net applications</li>
<li>Proven stability for .NET Framework workloads</li>
<li>Configuration-based setup with minimal code changes</li>
</ul>
</li>
<li>
<p><strong>Direct NuGet Package (this article):</strong> Manual log event creation</p>
<ul>
<li>Full control over log event structure</li>
<li>Useful for custom logging scenarios</li>
<li>Requires more code for each log entry</li>
<li>Best for edge cases or non-.NET integration</li>
</ul>
</li>
</ul></div>
</aside>

**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.

><i class="fal fa-file-archive" aria-hidden="true"></i> If you want to get started even faster, download the [FileWriterSample](http://download.integrationsoftware.se/Samples/Log%20Agent/IM.LogAgent.FileWriterSample.zip)<sup><i class="fal fa-arrow-up-right-from-square" aria-hidden="true"></i></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].

## <i class="fal fa-forward-step" aria-hidden="true"></i> 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  

## <i class="fal fa-forward-step" aria-hidden="true"></i> Step 2: Add NuGet package reference

<span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> 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><i class="fal fa-arrow-up-right-from-square" aria-hidden="true"></i></sup>:

* <i class="fal fa-box-full" aria-hidden="true"></i> [Nodinite.Libraries.Contracts.LogRestApi](https://www.nuget.org/packages/Nodinite.Libraries.Contracts.LogRestApi)<sup><i class="fal fa-arrow-up-right-from-square" aria-hidden="true"></i></sup>
  * [MIT License](https://download.nodinite.com/public/MIT-LICENSE.txt)<sup><i class="fal fa-arrow-up-right-from-square" aria-hidden="true"></i></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 <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span>, use version 5.x or later. For Integration Manager, use version 4.x.

## <i class="fal fa-forward-step" aria-hidden="true"></i> 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 <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> [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][].

## <i class="fal fa-hand-point-right" aria-hidden="true"></i> Next Steps

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

## <i class="fal fa-link-horizontal" aria-hidden="true"></i> Related Topics

* <i class="fal fa-file" aria-hidden="true"></i> [Message Types][]  
* <i class="fal fa-box-archive" aria-hidden="true"></i> [Log Agents][] - Events and messages  
* <i class="fal fa-hard-drive" aria-hidden="true"></i> [Logging Service][] - Processes (indexing) the messages  
* <i class="fal fa-search" aria-hidden="true"></i> [Log Views][] - Manage [User][Users] access to events and messages across platform  
* <i class="fal fa-database" aria-hidden="true"></i> [Log Databases][] - Keep as much data as you like  
* <i class="fal fa-sitemap" aria-hidden="true"></i> [Repository Model][]  

[1]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/CoreServices/LogAPI/SampleLogEvent/CreateNewProject.png
[2]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/CoreServices/LogAPI/SampleLogEvent/PackageManagerSettings.png
[3]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/CoreServices/LogAPI/SampleLogEvent/NodinitePackageSource.png
[4]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/CoreServices/LogAPI/SampleLogEvent/ManageNuGetPackages.png
[5]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/CoreServices/LogAPI/SampleLogEvent/SelectNuGetPackage.png
[6]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/CoreServices/LogAPI/SampleLogEvent/TypeLogEvent.png

[Asynchronous Logging]:https://docs.nodinite.com/core-services/log-api/features/asynchronous-logging/
[BPM]:https://docs.nodinite.com/repository-model/bpms/overview/
[Context Options]:https://docs.nodinite.com/core-services/log-event/features/context-options/
[Contracts]:https://docs.nodinite.com/getting-started/repository/contracts/overview/
[Endpoint Directions]:https://docs.nodinite.com/core-services/log-event/features/endpoint-directions/
[Endpoints]:https://docs.nodinite.com/repository-model/endpoints/overview/
[EndpointTypes]:https://docs.nodinite.com/core-services/log-event/features/endpoint-types/
[EventDirections]:https://docs.nodinite.com/core-services/log-event/features/event-directions/
[Generate Log Events]:https://docs.nodinite.com/core-services/log-api/troubleshooting/faq-generate-log-events/
[JSON Log Event]:https://docs.nodinite.com/core-services/log-event/features/json-log-event/
[Log Agents]:https://docs.nodinite.com/administration/log-management/log-agents/features/what-is-a-log-agent/
[Log Databases]:https://docs.nodinite.com/core-services/log-databases/overview/
[Log Event]:https://docs.nodinite.com/core-services/log-event/overview/
[Log Event Processing]:https://docs.nodinite.com/core-services/log-event/overview/
[Log Status Codes]:https://docs.nodinite.com/administration/log-management/log-agents/features/what-is-a-log-status-code/
[Log using REST]:https://docs.nodinite.com/core-services/log-api/features/log-using-rest/
[Log Views]:https://docs.nodinite.com/administration/log-management/log-views/features/what-is-a-log-view/
[Log4Net Appender]:https://docs.nodinite.com/logging-and-monitoring/log4net-appender/overview/
[LogAPI]:https://docs.nodinite.com/core-services/log-api/overview/
[Logging Service]:https://docs.nodinite.com/core-services/logging-service/overview/
[Message Types]:https://docs.nodinite.com/repository-model/message-types/overview/
[Non-Events Monitoring]:https://docs.nodinite.com/logging-and-monitoring/non-events/overview/
[Pickup Service]:https://docs.nodinite.com/logging-and-monitoring/pickup-logevents-service/overview/
[Repository Model]:https://docs.nodinite.com/repository-model/overview/
[Search Field Expressions]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/overview/
[Search Fields]:https://docs.nodinite.com/administration/log-management/search-fields/features/what-is-a-search-field/
[Serilog]:https://docs.nodinite.com/logging-and-monitoring/serilog/overview/
[Serilog Blob Storage]:https://docs.nodinite.com/logging-and-monitoring/serilog/features/blob-storage/
[Serilog Event Hub]:https://docs.nodinite.com/logging-and-monitoring/serilog/features/event-hub/
[Serilog File]:https://docs.nodinite.com/logging-and-monitoring/serilog/features/file/
[Serilog Log API]:https://docs.nodinite.com/logging-and-monitoring/serilog/features/log-api/
[Serilog ServiceBus]:https://docs.nodinite.com/logging-and-monitoring/serilog/features/servicebus/
[Users]:https://docs.nodinite.com/administration/access-management/users/features/what-is-a-user/