Tutorial Serilog & Elastic Search

18. 12. 14
posted by: Admin
Hits: 187

Tutorial Serilog & Elastic Search

Serilog digunakan u/ menyimpan Log, misalnya jika terjadi error, maka akan terbentuk file log yg berisi keterangan penyebab error.

---Command prompt folder aplikasi WebApplication
dotnet add package Serilog
dotnet add package Serilog.Exceptions
dotnet add package Serilog.Sinks.Elasticsearch
dotnet add package Serilog.Extensions.logging
dotnet add package Serilog.Sinks.Console
dotnet add package Serilog.aspnetcore

---Di Program.cs

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Hosting.Builder;
//using Microsoft.AspNetCore.Hosting.IWebHost;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Serilog;
using Serilog.AspNetCore;
using Serilog.Events;
using Serilog.Exceptions;
using Serilog.Sinks.Elasticsearch;
using Serilog.Sinks.RollingFile;
using Serilog.Sinks.File;
using Serilog.Sinks.PeriodicBatching;
using Serilog.Sinks.SystemConsole;
using Serilog.Extensions.Logging;

namespace WebApplication3
public class Program
public static int Main(string[] args)
var elasticsearchSinkOptions = new ElasticsearchSinkOptions(new Uri("http://localhost"))
MinimumLogEventLevel = LogEventLevel.Error,
IndexFormat = "latihan_asp3",
TypeName = "logException",
AutoRegisterTemplate = true,
BufferBaseFilename = @"C:\AspNetCoreLog\ElasticBuffer"

Log.Logger = new LoggerConfiguration()
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
.WriteTo.RollingFile(@"C:\AspNetCoreLog\LatihanASP3-{date}.log", LogEventLevel.Warning)

Log.Information("Starting web host");
return 0;
catch (Exception ex)
Log.Fatal(ex, "Host terminated unexpectedly");
return 1;

public static IWebHost BuildWebHost(string[] args) =>

--Di HomeController.cs (u/ pengujian hasil Serilog) :
var ghi = 1;
var jkl = 3;
ghi = jkl / 0;


0 #7 Jetta 2019-03-13 20:03
If some one desires to be updated with most recent technologies after
that he must be visit this site and be up to date every day.

My web page - Isiah: https://docbao123.blogspot.com/
0 #6 Ila 2019-03-09 12:58
Hi! Do you know if they make any plugins to help with SEO?
I'm trying to get my blog to rank for some targeted keywords but I'm not seeing very good gains.
If you know of any please share. Appreciate it!

Feel free to surf to my homepage :: {1998 mệnh gì: https://biensoxe.com/sinh-nam-1998-menh-tuoi-gi/
0 #5 Wiley 2019-03-08 08:13
With havin so much written content do you ever run into any problems
of plagorism or copyright infringement? My
site has a lot of exclusive content I've either written myself or outsourced but it looks
like a lot of it is popping it up all over the internet without my permission. Do you
know any ways to help stop content from being stolen? I'd really
appreciate it.

My webpage; đổi
lịch âm sang dương năm 1992: https://doilichamduong.com/
0 #4 Pearlene 2019-03-07 22:53
Your way of telling all in this article is actually good,
all can effortlessly understand it, Thanks a lot.

my webpage; {bói tình duyên vợ chồng: https://coituoivochong.com/xem-hop-tuoi-chong-2000-vo-1995/
0 #3 Jacelyn 2019-02-13 10:21
Hi my name is Jacelyn. Few days ago. i published a
article about the best gynecological clinic address in Hanoi.
Hope you read and feedback your review to
me. Tks. Here is my article link: http://bit.ly/2STmuTE

Also visit my webpage ... phong kham phu khoa: https://issuu.com/giomuaodau/docs/check_list_nh_n_di_n_ph_ng_kh_m_ph_
0 #2 Maurine 2019-02-12 18:34
Unquestionably imagine that that you said.
Your favourite reason seemed to be at the net the easiest factor to take note of.
I say to you, I certainly get irked even as other people think
about worries that they plainly don't recognise about. You controlled to hit the nail upon the top and outlined out
the whole thing with no need side effect , folks
could take a signal. Will likely be again to get more.
Thank you

my web site; {bói
tình duyên vợ chồng: https://coituoivochong.com/xem-hop-tuoi-chong-2018-vo-1996/
0 #1 Grant 2019-02-12 04:25
I am regular visitor, how are you everybody?
This article posted at this web site is in fact nice.

My web site :: Mittie: https://docbao123.blogspot.com/

Add comment

Security code