-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
56 lines (49 loc) · 1.88 KB
/
Program.cs
File metadata and controls
56 lines (49 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
using AutomapperExample.Converters.Automapper;
using AutoMapper;
using Serilog;
namespace AutomapperExample
{
class Program
{
static void Main(string[] args)
{
Console.SetWindowSize(200, Console.WindowHeight);
var log = new LoggerConfiguration()
.MinimumLevel.Verbose()
.WriteTo.ColoredConsole()
.CreateLogger();
// Load the maping profie
Mapper.Initialize(cfg => cfg.AddProfile<AssetProfile>());
// Fake an api model
var apiAsset = new Api.Models.Asset
{
Name = "Asset_01",
Id = 0111215454,
TimeStamp = DateTime.Now,
CustomApiProperty = "I am a random property"
};
// Log forwards
log.Verbose("Api > Business > Repository");
// Map api > business
var businessAsset = Mapper.Map<Business.Models.Asset>(apiAsset);
// Map business to repository
var repositoryAsset = Mapper.Map<Repository.Models.Asset>(businessAsset);
// Print
log.Information("Api {@Asset}", apiAsset);
log.Information("Business {@Asset}", businessAsset);
log.Information("Repository {@Asset}", repositoryAsset);
// Log backwards
log.Verbose("Repository > Business > Api");
// Map repository > business
businessAsset = Mapper.Map<Business.Models.Asset>(repositoryAsset);
// Map business > api
apiAsset = Mapper.Map<Api.Models.Asset>(businessAsset);
// Print
log.Information("Repository {@Asset}", repositoryAsset);
log.Information("Business {@Asset}", businessAsset);
log.Information("Api {@Asset}", apiAsset);
Console.ReadKey();
}
}
}